PHP code example of reactphp-x / concurrent
1. Go to this page and download the library: Download reactphp-x/concurrent library. Choose the download type require. 2. Extract the ZIP file and open the index.php. 3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
reactphp-x / concurrent example snippets
use ReactphpX\Concurrent\Concurrent;
use React\Promise\Deferred;
use React\EventLoop\Loop;
$concurrent = new Concurrent(10);
for ($i = 0; $i < 20; $i++) {
$concurrent->concurrent(function () use ($i) {
$deferred = new Deferred();
echo "Request $i\n";
Loop::addTimer($i, function () use ($deferred, $i) {
$deferred->resolve($i);
});
return $deferred->promise();
})->then(function ($result) {
echo "Result $result\n";
}, function ($error) {
$message = $error->getMessage();
echo "Error $message\n";
});
}