1
0
mirror of https://github.com/danog/parallel.git synced 2024-11-30 04:39:01 +01:00
parallel/examples/worker-pool-simple.php
2018-11-04 10:17:19 -06:00

25 lines
499 B
PHP

#!/usr/bin/env php
<?php
require \dirname(__DIR__) . '/vendor/autoload.php';
use Amp\Parallel\Worker;
use Amp\Promise;
$urls = [
'https://secure.php.net',
'https://amphp.org',
'https://github.com',
];
$promises = [];
foreach ($urls as $url) {
$promises[$url] = Worker\enqueueCallable('file_get_contents', $url);
}
$responses = Promise\wait(Promise\all($promises));
foreach ($responses as $url => $response) {
\printf("Read %d bytes from %s\n", \strlen($response), $url);
}