Stefan Gabos web developer extraordinaire
Zebra_cURL, a high performance PHP cURL library
-
Latest version1.0released onMarch 02, 2013
- 1. Overview
- 2. Features
- 3. Requirements
- 4. Installation
- 5. How to use
- 6. Download
- 7. Documentation
- 8. Changelog
- 9. Comments
Zebra_cURL is a high performance PHP library acting as a wrapper to PHP’s libcurl library, which not only allows the running of multiple requests at once asynchronously, in parallel, but also as soon as one thread finishes it can be processed right away without having to wait for the other threads in the queue to finish.
Also, each time a request is completed another one is added to the queue, thus keeping a constant number of threads running at all times and eliminating wasted CPU cycles from busy waiting. This result is a faster and more efficient way of processing large quantities of cURL requests (like fetching thousands of RSS feeds at once), drastically reducing processing time.
This script supports GET (with caching) and POST request, basic downloads as well as downloads from FTP servers, HTTP Authentication, and requests through proxy servers.
For maximum efficiency downloads are streamed (bytes downloaded are directly written to disk) removing the unnecessary strain from the server of having to read files into memory first, and then writing them to disk.
Zebra_cURL requires the PHP cURL extension to be enabled.
The code is heavily commented and generates no warnings/errors/notices when PHP’s error reporting level is set to E_ALL.
Features review
- supports GET (with caching) and POST request, basic downloads as well as downloads from FTP servers, HTTP Authentication, and requests through proxy servers
- allows the running of multiple requests at once asynchronously, in parallel, but also as soon as one thread finishes it can be processed right away without having to wait for the other threads in the queue to finish
- downloads are streamed (bytes downloaded are directly written to disk) removing the unnecessary strain from the server of having to read files into memory first, and then writing them to disk
- provides a very detailed information about the made requests
- has comprehensive documentation
- code is heavily commented and generates no warnings/errors/notices when PHP’s error reporting level is set to E_ALL
Requirements
PHP 5.0.2+ with the cURL extension installed
Installation
Download the latest version, unpack it, and put it in a place accessible to your scripts.
How to use
Fetch RSS feeds
<?php
function callback($result) {
// remember, the "body" property of $result is run through
// "htmlentities()", so you may need to "html_entity_decode" it
// show everything
print_r('<pre>');
print_r($result->info);
}
require 'path/to/Zebra_cURL.php';
// instantiate the Zebra_cURL class
$curl = new Zebra_cURL();
// cache results 60 seconds
$curl->cache('cache', 60);
// get RSS feeds of some popular tech websites
$curl->get(array(
'http://rss1.smashingmagazine.com/feed/',
'http://allthingsd.com/feed/',
'http://feeds.feedburner.com/nettuts',
'http://www.webmonkey.com/feed/',
'http://feeds.feedburner.com/alistapart/main',
), 'callback');
?>
Twitter Search
<?php
function callback($result) {
// results from twitter is json-encoded;
// remember, the "body" property of $result is run through
// "htmlentities()" so we need to "html_entity_decode" it
$result->body = json_decode(html_entity_decode($result->body));
// show everything
print_r('<pre>');
print_r($result);
}
// include the library
require 'path/to/Zebra_cURL.php';
// instantiate the Zebra_cURL class
$curl = new Zebra_cURL();
// cache results 60 seconds
$curl->cache('cache', 60);
// search twitter for the "jquery" hashtag
$curl->get('http://search.twitter.com/search.json?q=' . urlencode('#jquery'), 'callback');
?>
Download an image
<?php
// include the library
require 'path/to/Zebra_cURL.php';
// instantiate the Zebra_cURL class
$curl = new Zebra_cURL();
// download one of the official twitter image
$curl->download('https://abs.twimg.com/a/1362101114/images/resources/twitter-bird-callout.png', 'cache');
?>
Download
Zebra_cURL is distributed under the LGPL.
In plain English, this means that you have the right to view and to modify the source code of this software, but if you modify and distribute it, you are required to license your copy under a LGPL-compatible license, and to make the entire source code of your derivation available to anybody you distribute the software to.
You also have the right to use this software together with software thas has different licensing terms (including, but not limited to, commercial and closed-source software), and distribute the combined software, as long as state that your software contains portions licensed under the LGPL license, and provide information about where the LGPL licensed software can be downloaded.
If you distribute copies of this software you may not change the copyright or license of this software.
You may also like:
- Zebra_cURL, a a high performance PHP cURL library
- Zebra_Database, a MySQL database wrapper written in PHP
- Zebra_Form, a jQuery augmented PHP library for creating and validating forms
- Zebra_Image, a lightweight image manipulation library written in PHP
- Zebra_Mptt, a PHP implementation of the modified preorder tree traversal algorithm
- Zebra_Pagination, a generic pagination class written in PHP
- Zebra_Session, a wrapper for PHP's default session handling functions, using MySQL for storage
Documentation
|
Become a ninja. Read the comprehensive documentation. |
Changelog
Click on a version to expand/collapse information.
- version 1.0 (March 02, 2013)
-
- initial release;




I am a 32 year old web developer working from Bucharest, Romania. I am coding since I was 14 and I am extremely passionate about it. For the server side of things I use PHP/MySQL while on the front-end I write valid HTML 5, nice CSS and lots of JavaScript code using jQuery.
Hi;
Replyi want to show me Zebra-curl only $result->info but it show info and body. i put print_r(”); print_r($result->info); in callback function but it show body and info.
why?
Thanks.
i cannot confirm that…maybe you have multiple gets and multiple callback functions and one of them is displaying something and the other(s) something else
How to get contents of a webpage into a string, without automatically displaying webpage contents on calling $curl->get ?
Replythe “get” method (or any other of the methods) is not displaying anything on the screen…the content (and more) is passed to a callback function. see the examples.
Hi, if I use your example (http://stefangabos.ro/wp-content/docs/Zebra_cURL/Zebra_cURL/Zebra_cURL.html#methodget) and then just delete
in callback function it will still display the webpage content of fetched webpage.
I’ve also removed
but it still shows the webpage content simply on calling $curl->get…
Replyit looks like you are setting the CURLOPT_RETURNTRANSFER option to 0/FALSE somewhere
Reply