2015-12-05 06:50:32 +01:00
|
|
|
<?php
|
|
|
|
namespace Icicle\Concurrent\Worker;
|
|
|
|
|
2015-12-05 08:09:42 +01:00
|
|
|
use Icicle\Concurrent\Forking\Fork;
|
|
|
|
use Icicle\Concurrent\Threading\Thread;
|
|
|
|
|
2015-12-05 06:50:32 +01:00
|
|
|
/**
|
|
|
|
* The built-in worker factory type.
|
|
|
|
*/
|
|
|
|
class DefaultWorkerFactory implements WorkerFactory
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* {@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-12-05 08:09:42 +01:00
|
|
|
if (Thread::enabled()) {
|
2015-12-05 06:50:32 +01:00
|
|
|
return new WorkerThread();
|
|
|
|
}
|
|
|
|
|
2015-12-05 08:09:42 +01:00
|
|
|
if (Fork::enabled()) {
|
2015-12-05 06:50:32 +01:00
|
|
|
return new WorkerFork();
|
|
|
|
}
|
|
|
|
|
|
|
|
return new WorkerProcess();
|
|
|
|
}
|
|
|
|
}
|