diff --git a/lib/Context/Process.php b/lib/Context/Process.php index 3d722c8..e42b291 100644 --- a/lib/Context/Process.php +++ b/lib/Context/Process.php @@ -29,12 +29,14 @@ 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', 'Option1Value', 'Option2Value']. + * @param string|null $cwd Working directory. + * @param mixed[] $env Array of environment variables. * @param string $binary Path to PHP binary. Null will attempt to automatically locate the binary. * * @return \Amp\Parallel\Context\Process */ - public static function run($script, string $binary = null): self { - $process = new self($script, $binary); + public static function run($script, string $cwd = null, array $env = [], string $binary = null): self { + $process = new self($script, $cwd, $env, $binary); $process->start(); return $process; } @@ -42,13 +44,13 @@ 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', 'Option1Value', 'Option2Value']. - * @param string $binary Path to PHP binary. Null will attempt to automatically locate the binary. - * @param string $cwd Working directory. + * @param string|null $cwd Working directory. * @param mixed[] $env Array of environment variables. + * @param string $binary Path to PHP binary. Null will attempt to automatically locate the binary. * * @throws \Error If the PHP binary path given cannot be found or is not executable. */ - public function __construct($script, string $binary = null, string $cwd = "", array $env = []) { + public function __construct($script, string $cwd = null, array $env = [], string $binary = null) { $options = [ "html_errors" => "0", "display_errors" => "0", diff --git a/lib/Worker/DefaultWorkerFactory.php b/lib/Worker/DefaultWorkerFactory.php index 83dabb8..9c81432 100644 --- a/lib/Worker/DefaultWorkerFactory.php +++ b/lib/Worker/DefaultWorkerFactory.php @@ -19,10 +19,12 @@ class DefaultWorkerFactory implements WorkerFactory { */ public function create(): Worker { if (Thread::supported()) { - return new WorkerThread; + return new WorkerThread(BasicEnvironment::class); } return new WorkerProcess( + BasicEnvironment::class, + [], \getenv("AMP_PHP_BINARY") ?: (\defined("AMP_PHP_BINARY") ? \AMP_PHP_BINARY : null) ); } diff --git a/lib/Worker/WorkerProcess.php b/lib/Worker/WorkerProcess.php index e1a9c3b..2becb66 100644 --- a/lib/Worker/WorkerProcess.php +++ b/lib/Worker/WorkerProcess.php @@ -11,19 +11,19 @@ class WorkerProcess extends AbstractWorker { const SCRIPT_PATH = __DIR__ . "/Internal/worker-process.php"; /** - * @param string|null $binary Path to PHP binary. Null will attempt to automatically locate the 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(). + * @param string|null $binary Path to PHP binary. Null will attempt to automatically locate the binary. * * @throws \Error If the PHP binary path given cannot be found or is not executable. */ - public function __construct(string $binary = null, string $envClassName = BasicEnvironment::class, array $env = []) { + public function __construct(string $envClassName = BasicEnvironment::class, array $env = [], string $binary = null) { $script = [ self::SCRIPT_PATH, $envClassName, ]; - parent::__construct(new Process($script, $binary, __DIR__, $env)); + parent::__construct(new Process($script, null, $env, $binary)); } }