Skip to content

Commit 7a1c12e

Browse files
[Process] Fix process status tracking
1 parent 3cb242f commit 7a1c12e

File tree

2 files changed

+6
-15
lines changed

2 files changed

+6
-15
lines changed

Process.php

+3-15
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,6 @@ class Process implements \IteratorAggregate
8080
private WindowsPipes|UnixPipes $processPipes;
8181

8282
private ?int $latestSignal = null;
83-
private ?int $cachedExitCode = null;
8483

8584
private static ?bool $sigchild = null;
8685

@@ -1289,21 +1288,10 @@ protected function updateStatus(bool $blocking)
12891288
return;
12901289
}
12911290

1292-
$this->processInformation = proc_get_status($this->process);
1293-
$running = $this->processInformation['running'];
1294-
1295-
// In PHP < 8.3, "proc_get_status" only returns the correct exit status on the first call.
1296-
// Subsequent calls return -1 as the process is discarded. This workaround caches the first
1297-
// retrieved exit status for consistent results in later calls, mimicking PHP 8.3 behavior.
1298-
if (\PHP_VERSION_ID < 80300) {
1299-
if (!isset($this->cachedExitCode) && !$running && -1 !== $this->processInformation['exitcode']) {
1300-
$this->cachedExitCode = $this->processInformation['exitcode'];
1301-
}
1302-
1303-
if (isset($this->cachedExitCode) && !$running && -1 === $this->processInformation['exitcode']) {
1304-
$this->processInformation['exitcode'] = $this->cachedExitCode;
1305-
}
1291+
if ($this->processInformation['running'] ?? true) {
1292+
$this->processInformation = proc_get_status($this->process);
13061293
}
1294+
$running = $this->processInformation['running'];
13071295

13081296
$this->readPipes($running && $blocking, '\\' !== \DIRECTORY_SEPARATOR || !$running);
13091297

Tests/ProcessTest.php

+3
Original file line numberDiff line numberDiff line change
@@ -711,6 +711,9 @@ public function testProcessIsSignaledIfStopped()
711711
if ('\\' === \DIRECTORY_SEPARATOR) {
712712
$this->markTestSkipped('Windows does not support POSIX signals');
713713
}
714+
if (\PHP_VERSION_ID < 80300 && isset($_SERVER['GITHUB_ACTIONS'])) {
715+
$this->markTestSkipped('Transient on GHA with PHP < 8.3');
716+
}
714717

715718
$process = $this->getProcessForCode('sleep(32);');
716719
$process->start();

0 commit comments

Comments
 (0)