Created
November 26, 2014 11:32
-
-
Save redcapital/d85787623aed48e3476b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<? | |
require 'parallelcurl.php'; | |
$pc = new ParallelCurl(5); | |
// Bind $callback and $pc using "use()" construct, because we'll use them inside the closure | |
$callback = function($content, $url, $ch, $userParams) use (&$callback, $pc) { | |
// Print status of finished request | |
$i = $userParams['i']; | |
$httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE); | |
echo "Request index {$i}, got http code: $httpcode\n"; | |
if ($i == 20) { | |
// That's enough | |
echo "Finished!\n"; | |
return; | |
} | |
// Continue with next request | |
$pc->startRequest('example.com', $callback, ['i' => $i + 1]); | |
}; | |
// Queue our first request | |
$pc->startRequest('example.com', $callback, ['i' => 1]); | |
// Start actually processing requests, until request queue is empty | |
$pc->finishAllRequests(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment