2015-09-28 05:46:57 +02:00
|
|
|
#!/usr/bin/env php
|
|
|
|
<?php
|
|
|
|
require dirname(__DIR__).'/vendor/autoload.php';
|
|
|
|
|
2016-08-23 23:47:40 +02:00
|
|
|
use Amp\Parallel\Worker\DefaultWorkerFactory;
|
|
|
|
use Amp\Parallel\Example\BlockingTask;
|
2017-02-18 18:06:03 +01:00
|
|
|
use AsyncInterop\Loop;
|
2015-09-28 05:46:57 +02:00
|
|
|
|
2017-02-18 18:06:03 +01:00
|
|
|
Loop::execute(Amp\wrap(function () {
|
2015-12-05 08:09:42 +01:00
|
|
|
$factory = new DefaultWorkerFactory();
|
2015-09-28 05:46:57 +02:00
|
|
|
|
|
|
|
$worker = $factory->create();
|
|
|
|
$worker->start();
|
|
|
|
|
2016-08-18 18:04:48 +02:00
|
|
|
$result = yield $worker->enqueue(new BlockingTask('file_get_contents', 'https://google.com'));
|
2015-09-28 05:46:57 +02:00
|
|
|
printf("Read %d bytes\n", strlen($result));
|
|
|
|
|
2016-08-18 18:04:48 +02:00
|
|
|
$code = yield $worker->shutdown();
|
2015-09-28 05:46:57 +02:00
|
|
|
printf("Code: %d\n", $code);
|
2017-02-18 18:06:03 +01:00
|
|
|
}));
|