diff --git a/lib/Context/Process.php b/lib/Context/Process.php index 0e07e992..29565e03 100644 --- a/lib/Context/Process.php +++ b/lib/Context/Process.php @@ -26,10 +26,11 @@ class Process implements Context { /** * @param string|array $script Path to PHP script or array with first element as path and following elements options * to the PHP script (e.g.: ['bin/worker', '-eOptionValue', '-nOptionValue']. + * @param string $binary Path to PHP binary. Defaults to \PHP_BINARY. * @param string $cwd Working directory. * @param mixed[] $env Array of environment variables. */ - public function __construct($script, string $cwd = "", array $env = []) { + public function __construct($script, string $binary = \PHP_BINARY, string $cwd = "", array $env = []) { $options = [ "html_errors" => "0", "display_errors" => "0", @@ -44,7 +45,7 @@ public function __construct($script, string $cwd = "", array $env = []) { $options = (\PHP_SAPI === "phpdbg" ? " -b -qrr " : " ") . $this->formatOptions($options); $separator = \PHP_SAPI === "phpdbg" ? " -- " : " "; - $command = \escapeshellarg(\PHP_BINARY) . $options . $separator . $script; + $command = \escapeshellarg($binary) . $options . $separator . $script; $processOptions = []; diff --git a/lib/Worker/DefaultWorkerFactory.php b/lib/Worker/DefaultWorkerFactory.php index 77c482e1..2269bd0d 100644 --- a/lib/Worker/DefaultWorkerFactory.php +++ b/lib/Worker/DefaultWorkerFactory.php @@ -22,6 +22,11 @@ public function create(): Worker { return new WorkerThread; } - return new WorkerProcess; + $binary = \getenv("AMP_PHP_BINARY"); + if (!$binary && \defined("AMP_PHP_BINARY")) { + $binary = \AMP_PHP_BINARY; + } + + return new WorkerProcess($binary ?: \PHP_BINARY); } } diff --git a/lib/Worker/WorkerProcess.php b/lib/Worker/WorkerProcess.php index 8b42c1d7..25a8d33c 100644 --- a/lib/Worker/WorkerProcess.php +++ b/lib/Worker/WorkerProcess.php @@ -9,17 +9,18 @@ */ class WorkerProcess extends AbstractWorker { /** + * @param string $binaryPath Path to PHP Binary. Defaults to value of \PHP_BINARY. * @param string $envClassName Name of class implementing \Amp\Parallel\Worker\Environment to instigate. * Defaults to \Amp\Parallel\Worker\BasicEnvironment. * @param mixed[] $env Array of environment variables to pass to the worker. Empty array inherits from the current * PHP process. See the $env parameter of \Amp\Process\Process::__construct(). */ - public function __construct(string $envClassName = BasicEnvironment::class, array $env = []) { + public function __construct(string $binaryPath = \PHP_BINARY, string $envClassName = BasicEnvironment::class, array $env = []) { $dir = \dirname(__DIR__, 2) . '/bin'; $script = [ $dir . "/worker", "-e" . $envClassName, ]; - parent::__construct(new Process($script, $dir, $env)); + parent::__construct(new Process($script, $binaryPath, $dir, $env)); } }