1 | <?php |
||
15 | class ParentRuntime |
||
16 | { |
||
17 | /** @var bool */ |
||
18 | protected static $isInitialised = false; |
||
19 | |||
20 | /** @var string */ |
||
21 | protected static $autoloader; |
||
22 | |||
23 | /** @var string */ |
||
24 | protected static $childProcessScript; |
||
25 | |||
26 | protected static $currentId = 0; |
||
27 | |||
28 | protected static $myPid = null; |
||
29 | |||
30 | public static function init(string $autoloader = null) |
||
50 | |||
51 | /** |
||
52 | * @param \Spatie\Async\Task|callable $task |
||
53 | * @param int|null $outputLength |
||
54 | * |
||
55 | * @return \Spatie\Async\Process\Runnable |
||
56 | */ |
||
57 | public static function createProcess($task, ?int $outputLength = null, ?string $binary = 'php'): Runnable |
||
58 | { |
||
59 | if (! self::$isInitialised) { |
||
60 | self::init(); |
||
61 | } |
||
62 | |||
63 | if (! Pool::isSupported()) { |
||
64 | return SynchronousProcess::create($task, self::getId()); |
||
65 | } |
||
66 | |||
67 | $process = new Process([ |
||
68 | $binary, |
||
69 | self::$childProcessScript, |
||
70 | self::$autoloader, |
||
71 | self::encodeTask($task), |
||
72 | $outputLength, |
||
73 | ]); |
||
74 | |||
75 | return ParallelProcess::create($process, self::getId()); |
||
76 | } |
||
77 | |||
78 | /** |
||
79 | * @param \Spatie\Async\Task|callable $task |
||
80 | * |
||
81 | * @return string |
||
82 | */ |
||
83 | public static function encodeTask($task): string |
||
91 | |||
92 | public static function decodeTask(string $task) |
||
96 | |||
97 | protected static function getId(): string |
||
107 | } |
||
108 |
In PHP, under loose comparison (like
==
, or!=
, orswitch
conditions), values of different types might be equal.For
string
values, the empty string''
is a special case, in particular the following results might be unexpected: