Skip to content

Instantly share code, notes, and snippets.

@redcapital
Created November 26, 2014 11:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save redcapital/d85787623aed48e3476b to your computer and use it in GitHub Desktop.
Save redcapital/d85787623aed48e3476b to your computer and use it in GitHub Desktop.
<?
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