2015-08-14 19:25:07 +02:00
|
|
|
<?php
|
|
|
|
namespace Icicle\Concurrent\Worker;
|
|
|
|
|
2015-08-28 05:51:50 +02:00
|
|
|
/**
|
|
|
|
* The built-in worker factory type.
|
|
|
|
*/
|
|
|
|
class WorkerFactory implements WorkerFactoryInterface
|
2015-08-14 19:25:07 +02:00
|
|
|
{
|
2015-08-28 05:51:50 +02:00
|
|
|
/**
|
|
|
|
* {@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.
|
|
|
|
*/
|
2015-08-14 19:25:07 +02:00
|
|
|
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();
|
2015-08-14 19:25:07 +02:00
|
|
|
}
|
|
|
|
}
|