-
Notifications
You must be signed in to change notification settings - Fork 1
/
ForkWorker.php
48 lines (42 loc) · 1.49 KB
/
ForkWorker.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
<?php
namespace Aternos\Taskmaster\Environment\Fork;
use Aternos\Taskmaster\Proxy\ProcessProxy;
use Aternos\Taskmaster\Worker\Instance\WorkerInstanceInterface;
use Aternos\Taskmaster\Worker\SocketWorker;
/**
* Class ForkWorker
*
* The fork worker forks the php process using the pcntl extension.
* The pcntl extension is required for this worker, but not available in all environments.
* A {@link ProcessProxy} can be used to start the fork worker in a separate CLI process.
*
* @see https://www.php.net/manual/en/function.pcntl-fork.php
* @package Aternos\Taskmaster\Environment\Fork
*/
class ForkWorker extends SocketWorker
{
/**
* @return bool
*/
public static function isSupported(): bool
{
if (!extension_loaded("pcntl")) {
return false;
}
// GRPC only supports forks if explicitly enabled using the GRPC_ENABLE_FORK_SUPPORT environment variable
// see https://github.com/grpc/grpc/issues/13412
// If you don't use GRPC, but have the extension loaded, you can always define your workers manually
// or override the automatic worker selection using the TASKMASTER_WORKER environment variable
if (extension_loaded("grpc") && getenv("GRPC_ENABLE_FORK_SUPPORT") !== "1") {
return false;
}
return true;
}
/**
* @return WorkerInstanceInterface
*/
public function createInstance(): WorkerInstanceInterface
{
return new ForkWorkerInstance($this->options);
}
}