Created
June 2, 2021 02:28
-
-
Save jshensh/40530efefa5cfa79a3747673660dd2b2 to your computer and use it in GitHub Desktop.
Multi Curl Example
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
<?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) | |
]]); | |
} |
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
<?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