Skip to content

Instantly share code, notes, and snippets.

@jshensh
Created June 2, 2021 02:28
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 jshensh/40530efefa5cfa79a3747673660dd2b2 to your computer and use it in GitHub Desktop.
Save jshensh/40530efefa5cfa79a3747673660dd2b2 to your computer and use it in GitHub Desktop.
Multi Curl Example
<?php
// composer require jshensh/php-curl-class
require_once('./vendor/autoload.php');
use CustomCurl\Client;
var_dump(microtime(true));
$pool = [];
for ($i = 0; $i < 10; $i++) {
$pool["test{$i}"] = Client::init('http://127.0.0.1/sleep.php');
}
foreach (Client::multi($pool, ['concurrency' => 3]) as $k => $curlObj) {
var_dump([$k => [
'status' => $curlObj->getStatus(),
'now' => microtime(true)
]]);
}
<?php
sleep(2);
var_dump(microtime(true));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment