mirror of
https://github.com/danog/parallel.git
synced 2024-12-02 17:52:14 +01:00
31 lines
934 B
PHP
31 lines
934 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;
|
|
}
|
|
|
|
return new WorkerProcess(
|
|
\getenv("AMP_PHP_BINARY") ?:
|
|
\defined("AMP_PHP_BINARY") ? \AMP_PHP_BINARY : null
|
|
);
|
|
}
|
|
}
|