parallel/lib/Worker/DefaultWorkerFactory.php
Aaron Piotrowski 8decdceb5d
Reorder Process constructor params
Shifted $binary to the end as it should rarely be needed.
2017-12-12 21:06:11 -06:00

32 lines
1002 B
PHP

<?php
namespace Amp\Parallel\Worker;
use Amp\Parallel\Context\Thread;
/**
* 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 WorkerProcess will be created.
*
* \Amp\Parallel\Forking\WorkerFork is not used in the default factory since forking a process for workers is very
* sensitive to timing and process state and should be used only by the application designer if desired.
*/
public function create(): Worker {
if (Thread::supported()) {
return new WorkerThread(BasicEnvironment::class);
}
return new WorkerProcess(
BasicEnvironment::class,
[],
\getenv("AMP_PHP_BINARY") ?: (\defined("AMP_PHP_BINARY") ? \AMP_PHP_BINARY : null)
);
}
}