1
0
mirror of https://github.com/danog/parallel.git synced 2024-11-30 04:39:01 +01:00
parallel/examples/worker.php

24 lines
578 B
PHP
Raw Normal View History

2015-09-28 05:46:57 +02:00
#!/usr/bin/env php
<?php
require dirname(__DIR__).'/vendor/autoload.php';
use Icicle\Concurrent\Worker\WorkerFactory;
use Icicle\Coroutine;
use Icicle\Examples\Concurrent\BlockingTask;
use Icicle\Loop;
Coroutine\create(function () {
$factory = new WorkerFactory();
$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);
})->done();
Loop\run();