-
New Class: cURL
Here’s a quick release. I’ve been doing a lot of scraping work lately and of course use a cURL class. There’s plenty of cURL classes out there, and here’s another. I plan on evolving the class (joining multicurl into curl) and taking advantage of PHP 5.3 lambdas.
<?phprequire_once("../src/curl.php");
$session = new curl();
$m1 = new curl_request();
$m1->set_url("http://google.com/");$r1 = $session->run($m1); // returns a curl_response object
echo $r1->status_code;
?>
[Mar 8, 2010] I’ve merged multicurl into the curl class. Now if you specify a callback it will assume you want asynchronous results, if you don’t it will return the results synchronously as normal. I’ve also added the curl_request/curl_response classes which wrap common functionality. I added an example of multicurl downloading multiple pages at once. This example also uses PHP 5.3 lambda’s, but isn’t required (defaults to call_user_func_array in versions below 5.3).
<?phprequire_once("../src/curl.php");
$session = new curl();
$m1 = new curl_request();
$m1->set_url("http://www.youtube.com/");$session->run($m1, function($r1) use(&$session, &$m1)
{
print "[youtube] Loaded home page.\n";for($i = 1; $i <= 5; ++$i)
{
$m1->set_url("http://www.youtube.com/videos?p=" . $i);$session->run($m1, function($r1) use($i)
{
print "[youtube] Loaded video page {$i} ({$r1->status_code}).\n";
});
}
});while(true)
{
$session->update();
echo "."; // debug
usleep(20000);
}?>
Links:
More found on the work page, and more to come!