Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: symfony/process
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v6.4.3
Choose a base ref
...
head repository: symfony/process
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v6.4.4
Choose a head ref
  • 5 commits
  • 3 files changed
  • 5 contributors

Commits on Feb 9, 2024

  1. Verified

    This commit was signed with the committer’s verified signature.
    antfu Anthony Fu
    Copy the full SHA
    7e2c857 View commit details

Commits on Feb 12, 2024

  1. Merge branch '5.4' into 6.4

    * 5.4:
      Update configuration path in help message
      [Validator] Review Albanian translation
      [Process] Fix Inconsistent Exit Status in proc_get_status for PHP Versions Below 8.3
      [Validator] Update Czech (cz) translation
      Sync translations
      Review portuguese translations
      [Validator] Fix fields without constraints in `Collection`
      deal with fields for which no constraints have been configured
    derrabus committed Feb 12, 2024

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature.
    Copy the full SHA
    d4fd4a8 View commit details
  2. Verified

    This commit was signed with the committer’s verified signature.
    antfu Anthony Fu
    Copy the full SHA
    4fdf340 View commit details

Commits on Feb 13, 2024

  1. Merge branch '5.4' into 6.4

    * 5.4:
      [Process] Fix failing tests causing segfaults
    xabbuh committed Feb 13, 2024

    Verified

    This commit was signed with the committer’s verified signature.
    antfu Anthony Fu
    Copy the full SHA
    8bda0be View commit details

Commits on Feb 20, 2024

  1. Verified

    This commit was signed with the committer’s verified signature.
    antfu Anthony Fu
    Copy the full SHA
    710e278 View commit details
Showing with 69 additions and 1 deletion.
  1. +1 −1 ExecutableFinder.php
  2. +14 −0 Process.php
  3. +54 −0 Tests/ProcessTest.php
2 changes: 1 addition & 1 deletion ExecutableFinder.php
Original file line number Diff line number Diff line change
@@ -72,7 +72,7 @@ public function find(string $name, ?string $default = null, array $extraDirs = [
}
}

$command = '\\' === \DIRECTORY_SEPARATOR ? 'where' : 'command -v';
$command = '\\' === \DIRECTORY_SEPARATOR ? 'where' : 'command -v --';
if (\function_exists('exec') && ($executablePath = strtok(@exec($command.' '.escapeshellarg($name)), \PHP_EOL)) && @is_executable($executablePath)) {
return $executablePath;
}
14 changes: 14 additions & 0 deletions Process.php
Original file line number Diff line number Diff line change
@@ -80,6 +80,7 @@ class Process implements \IteratorAggregate
private WindowsPipes|UnixPipes $processPipes;

private ?int $latestSignal = null;
private ?int $cachedExitCode = null;

private static ?bool $sigchild = null;

@@ -1291,6 +1292,19 @@ protected function updateStatus(bool $blocking)
$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
// retrieved exit status for consistent results in later calls, mimicking PHP 8.3 behavior.
if (\PHP_VERSION_ID < 80300) {
if (!isset($this->cachedExitCode) && !$running && -1 !== $this->processInformation['exitcode']) {
$this->cachedExitCode = $this->processInformation['exitcode'];
}

if (isset($this->cachedExitCode) && !$running && -1 === $this->processInformation['exitcode']) {
$this->processInformation['exitcode'] = $this->cachedExitCode;
}
}

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

if ($this->fallbackStatus && $this->isSigchildEnabled()) {
54 changes: 54 additions & 0 deletions Tests/ProcessTest.php
Original file line number Diff line number Diff line change
@@ -1553,6 +1553,60 @@ public function testEnvCaseInsensitiveOnWindows()
}
}

public function testMultipleCallsToProcGetStatus()
{
$process = $this->getProcess('echo foo');
$process->start(static function () use ($process) {
return $process->isRunning();
});
while ($process->isRunning()) {
usleep(1000);
}
$this->assertSame(0, $process->getExitCode());
}

public function testFailingProcessWithMultipleCallsToProcGetStatus()
{
$process = $this->getProcess('exit 123');
$process->start(static function () use ($process) {
return $process->isRunning();
});
while ($process->isRunning()) {
usleep(1000);
}
$this->assertSame(123, $process->getExitCode());
}

/**
* @group slow
*/
public function testLongRunningProcessWithMultipleCallsToProcGetStatus()
{
$process = $this->getProcess('sleep 1 && echo "done" && php -r "exit(0);"');
$process->start(static function () use ($process) {
return $process->isRunning();
});
while ($process->isRunning()) {
usleep(1000);
}
$this->assertSame(0, $process->getExitCode());
}

/**
* @group slow
*/
public function testLongRunningProcessWithMultipleCallsToProcGetStatusError()
{
$process = $this->getProcess('sleep 1 && echo "failure" && php -r "exit(123);"');
$process->start(static function () use ($process) {
return $process->isRunning();
});
while ($process->isRunning()) {
usleep(1000);
}
$this->assertSame(123, $process->getExitCode());
}

/**
* @group transient-on-windows
*/