• Eric Muyser

    "Success is the progressive realization of a worthy ideal" - Napoleon Hill

    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.

    1.  
    2.  
    3. <?php

    4. require_once("../src/curl.php");

    5. $session = new curl();

    6. $m1 = new curl_request();

    7. $m1->set_url("http://google.com/");

    8. $r1 = $session->run($m1); // returns a curl_response object

    9. echo $r1->status_code;

    10. ?>

     

    [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).

    1.  
    2.  
    3. <?php

    4. require_once("../src/curl.php");

    5. $session = new curl();

    6. $m1 = new curl_request();

    7. $m1->set_url("http://www.youtube.com/");

    8. $session->run($m1, function($r1) use(&$session, &$m1)

    9. {

    10. print "[youtube] Loaded home page.\n";

    11. for($i = 1; $i <= 5; ++$i)

    12. {

    13. $m1->set_url("http://www.youtube.com/videos?p=" . $i);

    14. $session->run($m1, function($r1) use($i)

    15. {

    16. print "[youtube] Loaded video page {$i} ({$r1->status_code}).\n";

    17. });

    18. }

    19. });

    20. while(true)

    21. {

    22. $session->update();

    23. echo "."; // debug

    24. usleep(20000);

    25. }

    26. ?>

     

    Links:

     

    More found on the work page, and more to come!