1
0
mirror of https://github.com/danog/parallel.git synced 2024-12-03 10:07:49 +01:00
parallel/src/Worker/WorkerFactory.php

29 lines
725 B
PHP
Raw Normal View History

<?php
namespace Icicle\Concurrent\Worker;
/**
* The built-in worker factory type.
*/
class WorkerFactory implements WorkerFactoryInterface
{
/**
* {@inheritdoc}
*
* 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 function create()
{
2015-08-27 16:10:08 +02:00
if (extension_loaded('pthreads')) {
return new WorkerThread();
}
if (extension_loaded('pcntl')) {
return new WorkerFork();
}
return new WorkerProcess();
}
}