So, let’s continue to develop Mass PageRank Checker tool. I will use CodeIgniter (CI) PHP framework for it. It’s really simple and very powerful thing. But first I need Curl library for CI to make easier working with HTTP queries.
In brief, the library must do the following things:
- Send HTTP GET/POST requests and receive HTTP responses.
- Get information about queries like HTTP error code, total time for operation, number of sent/received bytes for operation, etc.
- Handle the errors.
I just wrote this library, you can download it here.
To use it just copy Curl.php to CI’s system/application/libraries folder, curl_lang.php to CI’s system/application/language/english folder and load it from your controllers:
$this->load->library('curl');
For example let’s simulate the search in Google:
$keyword = 'travel';
$this->load->library('curl');
$this->curl->open();
$content = $this->curl->http_get("http://www.google.com/search?q=$keyword");
$this->curl->close();
echo $content;
This is very simple example. At this moment the library has not powerful features. Here the list of what you can do and how you can do using Curl library:
- Set additional options like User-Agent (MSIE 7.0 by default), timeout for operations in seconds (30 by default).
$this->curl->open(array('user_agent' => 'CURL library', 'timeout' => 60));
- Send HTTP GET query and get the content. Setting $headers_only = TRUE will cause you receive HTTP headers only. You can specify additional HTTP headers in $headers variable.
function http_get($url, $headers = array(), $headers_only = FALSE)
- Send HTTP POST query and get the content. POST parameters must be specified in $fields variable like ‘a=1&b=2&str=test%20example’
function http_post($url, $fields, $headers = array(), $headers_only = FALSE)
- There are a few functions for getting different information about query
function get_http_code()
function get_total_time()
function get_bytes_uploaded()
function get_bytes_downloaded()
function get_speed_upload()
function get_speed_download()
In the future I’m planning to add the following features to library: referer and autoreferer support, cookies, proxies, authorization, follow location feature, caching, file uploading, additional headers and may be some more.
Posted on April 14th, 2008 at 1:11 pm
Wow. Great work, Alex! Thx