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

19 lines
497 B
PHP
Executable File

#!/usr/bin/env php
<?php
require \dirname(__DIR__) . '/vendor/autoload.php';
use Amp\Parallel\Worker\CallableTask;
use Amp\Parallel\Worker\DefaultWorkerFactory;
Amp\Loop::run(function () {
$factory = new DefaultWorkerFactory();
$worker = $factory->create();
$result = yield $worker->enqueue(new CallableTask('file_get_contents', 'https://google.com'));
\printf("Read %d bytes\n", \strlen($result));
$code = yield $worker->shutdown();
\printf("Code: %d\n", $code);
});