create() public method

The type of worker created depends on the extensions available. If multi-threading is enabled, a WorkerThread will be created. If threads are not available, a WorkerFork will be created if forking is available, otherwise a WorkerProcess will be created.
public create ( ) : Worker
return Worker
Ejemplo n.º 1
0
#!/usr/bin/env php
<?php 
require dirname(__DIR__) . '/vendor/autoload.php';
use Icicle\Concurrent\Worker\DefaultWorkerFactory;
use Icicle\Coroutine;
use Icicle\Examples\Concurrent\BlockingTask;
use Icicle\Loop;
Coroutine\create(function () {
    $factory = new DefaultWorkerFactory();
    $worker = $factory->create();
    $worker->start();
    $result = (yield from $worker->enqueue(new BlockingTask('file_get_contents', 'https://google.com')));
    printf("Read %d bytes\n", strlen($result));
    $code = (yield from $worker->shutdown());
    printf("Code: %d\n", $code);
})->done();
Loop\run();