1
0
mirror of https://github.com/danog/parallel.git synced 2024-11-26 20:34:40 +01:00
parallel/example/worker.php
Aaron Piotrowski d6a1b19b8e Update examples
2017-02-18 11:06:03 -06:00

21 lines
547 B
PHP
Executable File

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