Skip to main content

Curl HTTP Client 2.0

It’s been a while since I last updated my Curl HTTP Client class. That’s the class that we’ve been using for years now, for all kinds of site scrapping, bulk domain registration without API, … and even today we use it as a part of core in our brand new Payment system.

Since I had some spare time this weekend, I finally managed to merge some of updates we’ve created during all these years and put a class to github so I can do frequent updates regularly. Don’t worry, class has retained most of it’s previous functionality explained here so update to latest version shouldn’t cause any problem.

Here’s the GitHub page: Feel free to use it in your own projects and send in your comments.

Browser Detection Update

Long time ago I developed Browser Detection Class which is able to recognize most of popular browser/OS’s used today.

For example FF on my macbook pro would be recognized like this:
Mozilla Firefox 3.0.4 / Mac OS X

Very useful stuff in case you have to redirect your users to different pages depending of browser version or to maintain your own site browser/os usage statistics.

Today I had a chance to update it with support for Windows Vista, Google Chrome and iPhone.

You can download complete code with usage examples by following this link.

MySQL 5.x – Finally improved client

Looking at my favorite rss feeds today, I found this post on great MySQL Performance Blog:

…if you press CTRL-C MySQL Command Line Client will not exit but will terminate query being executed.

In other words, in previous versions of MySQL client program, if you issue a query and try to interrupt it by hitting CTRL-C, CTRL-C would actually kill MySQL client itself, but query still continue running in background! In this case the only solution to really kill that query is to find it’s ID on process list (by issuing “show full processlist” query), and then to kill it with a query like “kill 12345”, where 12345 is ID of query that you want to be killed. In other words, something like this:

mysql> select * from odm_result_keywords where keyword like '%foo%joe%';
bash-2.05b$ mysql -A --enable-local-infile -udinke -ppass mydb
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 1512 to server version: 4.1.18-log

Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

mysql> show full processlist;
| Id   | User  | Host                       | db                | Command | Time | State        | Info                                                               |
| 1486 | dinke | localhost                  | mydb | Query   |    3 | Sending data | select * from odm_result_keywords where keyword like '' |
1 row in set (0.00 sec)

mysql> kill 1486;

Thanks to changes in MySQL client program, all you have to do now is to hit CTRL-C, and query will be stopped immediately:

mysql> select domain from odm_result_keywords_de where whois_status is null and domain like '%.%.%';
Query aborted by Ctrl+C
ERROR 1317 (70100): Query execution was interrupted

For more information about this feature (as well as other changes in MySQL 5.0.25) please follow this link.

Firefox 2.0 Final

Almost one year after launch of version 1.5, and just a few days after very buggy RC 3, final version of Firefox 2.0 is finally available.

Firefox 2.0

According to release notes, new Firefox contains usability improvements, built-in phishing protection, spell checking, improved tabbed browsing and new JavaScript 1.7 under the hood.

After download (windows installation is 5.6MB) it install smoothly, without any problem with extensions etc.

However, my first impressions are not very good. I simple don’t like new default theme, something simmilar as “Go” button is added next to location bar and search bar, there is no longer close button to the far right side of tab bar, now you have close button added for each tab (like in Opera).

About new features, now firefox is able to remember your session (reopen all tabs you had before you’ve closed it). On my machine it is not enabled by default, but it can be easily turned on in ff options. Also, there is a new spell checker which is enabled by default with english dictionary. Very annoying if you mostly write in non english language, and don’t have dictionary support. Search bar is now able to list you suggestions soon after you star typing your keyword (simmilar as Google Suggest tool).

Regarding new options in menu, I haven’t noticed many changes. In History part there is a “Recently closed tabs” option, very usefull especially if you’ve closed some tab by mistake. Also themes and extensions are now reorganized under “Add-ons” menu, which is part of Tools menu. In Options menu there is a “feeds” tab where you can define how would you like to handle rss feeds, and in case you don’t have any feed reader installed, you can pick some of online readers (like Bloglines, Google Reader etc.).

All in all, I really liked ff 1.5 look and feel much more, but FF 2.0 have some interesting new features. Will give it a chance for a few days and see if I am going to keep it, or revert to goof old FF 1.5.x.x 🙂

Netvibes 2.0

My favorite Web 2.0 application Netvibes just came to second big revision with code name “Cinnamon”.

At first I was disappointed with changes. Although they announced tons of new features, I saw only small changes in user interface and few new modules. However, more changes are about to come, because Cinnamon is actually “a three-month release cycle, where you will see new features and upgrades throughout that time”.

So far I’ve noticed new splash screen, slightly changed interface, and couple of new modules like “Blog Search”, Video Search etc.

Blog Search
Blog Search

Netvibes u Akciji
Netvibes in Action

Spam Carma 2

If you run Word Press based blog, and getting a lot of spam comments on it, this plugin is right for you.

Unlike other spam killers (like Akismet plugin which behave badly with non english comments), Spam Carma 2 kills 100% of spam, and never have a problems with regular comments.

Spam Carma 2 contains several spam filters, where restriction for each of them can be set to higher or lower level. For example, there is a Stopwatch which make sure commenter has been on page for a certain number of seconds before commenting, Javascript Payload which embed a few Javascript commands in comment form (users with JS turned off only receives a small penalty) and plenty of other stuff like captcha check which is displayed only if commenter is not recognized as normal user.

Since I’ve installed it, Spam Carma killed more than 300 spam commenters without actually stopping any regular comment!

Curl HTTP Client

Frequently, in my daytime job I have to fetch data from various url’s, either by sending get or post request, binding to different IP address etc. Long time I used my own socket based HTTP class, although I wasn’t quite happy with perfomances and various other things with it. I already used curl cli tool (mostly for debugging purposes), but didn’t really liked it’s php api, so I’ve decided to take some spare time and make some kind of oop wrapper for it, which should be easier to use for easy stuff like sending get/post request etc.

I use this class several months since then, and it evolved over time whenever I needed some new feature. Since various of my colleagues found it very usefull (some of them even sent me new methods for it), I’ve decided to put it out for public. Recently I submitted a code to, and today got confirmation that class is officially approved.

Update 03/01/2007
New version 1.1 released with new features: fetch into file, upload, proxy etc.

Update 15/02/2008
New version 1.2 released with few bug fixes. New features are ability to send post string as string argument in send_post_data method, ability to accept gzipped content, close curl session etc.

Update 25/03/2013
Version 2.0 released. Pretty much the same features as old versions, but with updated code in order to match latest PHP changes. Code will be regularly updated on github.

You can download class and example files directly from gitgub

Here are few usage examples.

 * @version 2.0
 * @package
 * @copyright © 2013
 * @author Dragan Dinic 


$curl = new Curl_HTTP_Client();

//pretend to be Firefox 19.0 on Mac
$useragent = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:19.0) Gecko/20100101 Firefox/19.0";

//uncomment next two lines if you want to automatically manage cookies
//which will store them to file and send them on each http request
//$cookies_file = "/tmp/cookies.txt";

//Uncomment next line if you want to set credentials for basic http_auth
//$curl->set_credentials($username, $password);

//Uncomment next line if you want to set specific referrer

//if you want to send some post data
//form post data array like this one
$post_data = array('login' => 'pera', 'password' => 'joe', 'other_foo_field' => 'foo_value');
//or like a string: $post_data = 'login=pera&password=joe&other_foo_field=foo_value';

//and send request to Result page is stored in $html_data string
$html_data = $curl->send_post_data("", $post_data);

//You can also fetch data from somewhere using get method!
//Fetch html from url
$html_data = $curl->fetch_url("");

//if you have more than one IP on your server,
//you can also bind to specific IP address like ...
//$bind_ip = "";
//$curl->fetch_url("", $bind_ip);
//$html_data = $curl->send_post_data("", $post_data, $bind_ip);

//and there are many other things you can do like

//use proxy

//get http response code for last request
//$http_code = $curl->get_http_response_code();

//get last http request duration in sec
//$duration = $curl->get_request_duration();

Google Page Creator

Don’t know about you, but I have difficulties to follow up with all services Google announce almost each day. GMail, GMap, GTalk, GCal, GSpreadsheets, … and lately we got Google Page Creator.

Google Page Creator is another one Web 2.0 application, which allow us to create Web Pages in a snap. Like with others simmilar tools, you don’t have to know html or any other technology, all you need is your browser and little creativity. Unlike other tools Page Creator is very easy to use (thanks to very good Ajax implementation), so in as little as 5 minutes you can come up with your new Web Site. Such site will be indexed by google shortly, and will be hosted free on address like:

You can see results of my 5 minute Page Creatoru session here 🙂