From 400e5d9e3999ef667638f8194785f6ae00483e6d Mon Sep 17 00:00:00 2001 From: Lucas Bustamante Date: Wed, 7 Feb 2024 00:13:46 -0300 Subject: [PATCH 1/8] Cache exitcode on PHP 8.2 and lower --- src/Symfony/Component/Process/Process.php | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/Symfony/Component/Process/Process.php b/src/Symfony/Component/Process/Process.php index 7c4e925004dbf..869175955f6fd 100644 --- a/src/Symfony/Component/Process/Process.php +++ b/src/Symfony/Component/Process/Process.php @@ -1289,6 +1289,26 @@ protected function updateStatus(bool $blocking): void } $this->processInformation = proc_get_status($this->process); + + /* + * On PHP 8.2 and lower, when calling "proc_get_status" multiple times, + * the only real status code is the first one. The process starts with "-1". + * We essentially mimick PHP 8.3 proc_get_status behavior on lower versions + * by caching the exit status code when the process returns it, before the + * process is discarded. + */ + if (version_compare(PHP_VERSION, '8.3.0', '<')) { + static $cachedExitCode = null; + + if (is_null($cachedExitCode) && !$running && $this->processInformation['exitcode'] !== -1) { + $cachedExitCode = $this->processInformation['exitcode']; + } + + if (!is_null($cachedExitCode) && !$running && $this->processInformation['exitcode'] === -1) { + $this->processInformation['exitcode'] = $cachedExitCode; + } + } + $running = $this->processInformation['running']; $this->readPipes($running && $blocking, '\\' !== \DIRECTORY_SEPARATOR || !$running); From 7e8b115c74658ce47377b155641dd004a5e4c068 Mon Sep 17 00:00:00 2001 From: Lucas Bustamante Date: Wed, 7 Feb 2024 00:27:46 -0300 Subject: [PATCH 2/8] Update comment --- src/Symfony/Component/Process/Process.php | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/src/Symfony/Component/Process/Process.php b/src/Symfony/Component/Process/Process.php index 869175955f6fd..d46de1324985c 100644 --- a/src/Symfony/Component/Process/Process.php +++ b/src/Symfony/Component/Process/Process.php @@ -1291,12 +1291,10 @@ protected function updateStatus(bool $blocking): void $this->processInformation = proc_get_status($this->process); /* - * On PHP 8.2 and lower, when calling "proc_get_status" multiple times, - * the only real status code is the first one. The process starts with "-1". - * We essentially mimick PHP 8.3 proc_get_status behavior on lower versions - * by caching the exit status code when the process returns it, before the - * process is discarded. - */ + * In PHP < 8.3, "proc_get_status" only returns the correct exit status on the first call. + * Subsequent calls return -1 as the process is discarded. This workaround caches the first + * retrieved exit status for consistent results in later calls, mimicking PHP 8.3 behavior. + */ if (version_compare(PHP_VERSION, '8.3.0', '<')) { static $cachedExitCode = null; From b60834599ad3ab8f5aeec46da0bcee422610e683 Mon Sep 17 00:00:00 2001 From: Lucas Bustamante Date: Wed, 7 Feb 2024 00:31:48 -0300 Subject: [PATCH 3/8] Typo --- src/Symfony/Component/Process/Process.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Symfony/Component/Process/Process.php b/src/Symfony/Component/Process/Process.php index d46de1324985c..7ab2b2340238c 100644 --- a/src/Symfony/Component/Process/Process.php +++ b/src/Symfony/Component/Process/Process.php @@ -1290,6 +1290,8 @@ protected function updateStatus(bool $blocking): void $this->processInformation = proc_get_status($this->process); + $running = $this->processInformation['running']; + /* * In PHP < 8.3, "proc_get_status" only returns the correct exit status on the first call. * Subsequent calls return -1 as the process is discarded. This workaround caches the first @@ -1306,8 +1308,6 @@ protected function updateStatus(bool $blocking): void $this->processInformation['exitcode'] = $cachedExitCode; } } - - $running = $this->processInformation['running']; $this->readPipes($running && $blocking, '\\' !== \DIRECTORY_SEPARATOR || !$running); From 8b376d367598d0e96c303d27207b93ddd79931ea Mon Sep 17 00:00:00 2001 From: Lucas Bustamante Date: Wed, 7 Feb 2024 00:34:56 -0300 Subject: [PATCH 4/8] Code style --- src/Symfony/Component/Process/Process.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Symfony/Component/Process/Process.php b/src/Symfony/Component/Process/Process.php index 7ab2b2340238c..b643e9e1ed871 100644 --- a/src/Symfony/Component/Process/Process.php +++ b/src/Symfony/Component/Process/Process.php @@ -1292,19 +1292,19 @@ protected function updateStatus(bool $blocking): void $running = $this->processInformation['running']; - /* + /* * In PHP < 8.3, "proc_get_status" only returns the correct exit status on the first call. * Subsequent calls return -1 as the process is discarded. This workaround caches the first * retrieved exit status for consistent results in later calls, mimicking PHP 8.3 behavior. */ - if (version_compare(PHP_VERSION, '8.3.0', '<')) { + if (version_compare(\PHP_VERSION, '8.3.0', '<')) { static $cachedExitCode = null; - if (is_null($cachedExitCode) && !$running && $this->processInformation['exitcode'] !== -1) { + if (null === $cachedExitCode && !$running && $this->processInformation['exitcode'] !== -1) { $cachedExitCode = $this->processInformation['exitcode']; } - if (!is_null($cachedExitCode) && !$running && $this->processInformation['exitcode'] === -1) { + if (null !== $cachedExitCode && !$running && $this->processInformation['exitcode'] === -1) { $this->processInformation['exitcode'] = $cachedExitCode; } } From 93cbc4bdaf1ebe811ad7af9bddd3ea797501451a Mon Sep 17 00:00:00 2001 From: Lucas Bustamante Date: Wed, 7 Feb 2024 00:37:02 -0300 Subject: [PATCH 5/8] Code style --- src/Symfony/Component/Process/Process.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Symfony/Component/Process/Process.php b/src/Symfony/Component/Process/Process.php index b643e9e1ed871..7f12e20aac0b7 100644 --- a/src/Symfony/Component/Process/Process.php +++ b/src/Symfony/Component/Process/Process.php @@ -1299,11 +1299,11 @@ protected function updateStatus(bool $blocking): void */ if (version_compare(\PHP_VERSION, '8.3.0', '<')) { static $cachedExitCode = null; - + if (null === $cachedExitCode && !$running && $this->processInformation['exitcode'] !== -1) { $cachedExitCode = $this->processInformation['exitcode']; } - + if (null !== $cachedExitCode && !$running && $this->processInformation['exitcode'] === -1) { $this->processInformation['exitcode'] = $cachedExitCode; } From 1129b6414a3aa70cf010883192a614b2c61047fc Mon Sep 17 00:00:00 2001 From: Lucas Bustamante Date: Wed, 7 Feb 2024 00:38:56 -0300 Subject: [PATCH 6/8] Code style --- src/Symfony/Component/Process/Process.php | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/src/Symfony/Component/Process/Process.php b/src/Symfony/Component/Process/Process.php index 7f12e20aac0b7..3486b46491611 100644 --- a/src/Symfony/Component/Process/Process.php +++ b/src/Symfony/Component/Process/Process.php @@ -1292,19 +1292,17 @@ protected function updateStatus(bool $blocking): void $running = $this->processInformation['running']; - /* - * In PHP < 8.3, "proc_get_status" only returns the correct exit status on the first call. - * Subsequent calls return -1 as the process is discarded. This workaround caches the first - * retrieved exit status for consistent results in later calls, mimicking PHP 8.3 behavior. - */ + // In PHP < 8.3, "proc_get_status" only returns the correct exit status on the first call. + // Subsequent calls return -1 as the process is discarded. This workaround caches the first + // retrieved exit status for consistent results in later calls, mimicking PHP 8.3 behavior. if (version_compare(\PHP_VERSION, '8.3.0', '<')) { static $cachedExitCode = null; - if (null === $cachedExitCode && !$running && $this->processInformation['exitcode'] !== -1) { + if (null === $cachedExitCode && !$running && -1 !== $this->processInformation['exitcode']) { $cachedExitCode = $this->processInformation['exitcode']; } - if (null !== $cachedExitCode && !$running && $this->processInformation['exitcode'] === -1) { + if (null !== $cachedExitCode && !$running && -1 === $this->processInformation['exitcode']) { $this->processInformation['exitcode'] = $cachedExitCode; } } From 144796f3f11a5c8000857da567d7ec78d946dc95 Mon Sep 17 00:00:00 2001 From: Lucas Bustamante Date: Wed, 7 Feb 2024 00:40:07 -0300 Subject: [PATCH 7/8] Code style --- src/Symfony/Component/Process/Process.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Symfony/Component/Process/Process.php b/src/Symfony/Component/Process/Process.php index 3486b46491611..7daccc76688ae 100644 --- a/src/Symfony/Component/Process/Process.php +++ b/src/Symfony/Component/Process/Process.php @@ -1292,9 +1292,9 @@ protected function updateStatus(bool $blocking): void $running = $this->processInformation['running']; - // In PHP < 8.3, "proc_get_status" only returns the correct exit status on the first call. - // Subsequent calls return -1 as the process is discarded. This workaround caches the first - // retrieved exit status for consistent results in later calls, mimicking PHP 8.3 behavior. + // In PHP < 8.3, "proc_get_status" only returns the correct exit status on the first call. + // Subsequent calls return -1 as the process is discarded. This workaround caches the first + // retrieved exit status for consistent results in later calls, mimicking PHP 8.3 behavior. if (version_compare(\PHP_VERSION, '8.3.0', '<')) { static $cachedExitCode = null; From d7e0aeb094c78a19a951ba633ab8e761c72eb51f Mon Sep 17 00:00:00 2001 From: Lucas Bustamante Date: Wed, 7 Feb 2024 00:41:05 -0300 Subject: [PATCH 8/8] Code style --- src/Symfony/Component/Process/Process.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Symfony/Component/Process/Process.php b/src/Symfony/Component/Process/Process.php index 7daccc76688ae..7e6a77af1f0a2 100644 --- a/src/Symfony/Component/Process/Process.php +++ b/src/Symfony/Component/Process/Process.php @@ -1292,8 +1292,8 @@ protected function updateStatus(bool $blocking): void $running = $this->processInformation['running']; - // In PHP < 8.3, "proc_get_status" only returns the correct exit status on the first call. - // Subsequent calls return -1 as the process is discarded. This workaround caches the first + // In PHP < 8.3, "proc_get_status" only returns the correct exit status on the first call. + // Subsequent calls return -1 as the process is discarded. This workaround caches the first // retrieved exit status for consistent results in later calls, mimicking PHP 8.3 behavior. if (version_compare(\PHP_VERSION, '8.3.0', '<')) { static $cachedExitCode = null;