Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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