Skip to content

Commit b0687c9

Browse files
bug symfony#61401 [Process] Enhance hasSystemCallBeenInterrupted function for non-english locale (christianseel)
This PR was squashed before being merged into the 6.4 branch. Discussion ---------- [Process] Enhance hasSystemCallBeenInterrupted function for non-english locale | Q | A | ------------- | --- | Branch? | 6.4 | Bug fix? | yes | New feature? | no | Deprecations? | no | Issues | Related: PHPMailer/PHPMailer#3183 | License | MIT We've been facing an issue with PHPMailer (PHPMailer/PHPMailer#3183) where `stream_select()` returns false, but because our application uses `setlocale(LC_ALL, 'de_DE.UTF-8')`, the PHP warning does **NOT** contain the string `'interrupted system call'` which results in unexpected behavior (no retry happening). We did found a fix for this: PHPMailer/PHPMailer#3193 > I received a great hint by `@teefax` – who pointed out that the stream_select(): Unable to select part of the php warning message is not translated for other locales. Only the interrupted system call part is translated. > > That Unable to select is followed by an error number in square brackets. However that number can be different based on the operating system of the server. But PHP has a constant [SOCKET_EINTR](https://www.php.net/manual/en/sockets.constants.php#constant.socket-eintr) for that. > > So the recommendation is to check for the SOCKET_EINTR constant which is defined under Windows and UNIX-like platforms (if available on the platform) and use that with the other english warning text to catch those interrupted system calls for non-english locale applications. > > I left the existing check to avoid any potential unknown breaking change and extended the if-condition. As I known Symfony was using a similar approach, I'm recommending to apply this enhancement to the "interrupted check" as well. Commits ------- 013126d [Process] Enhance hasSystemCallBeenInterrupted function for non-english locale
2 parents fa2356a + 013126d commit b0687c9

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

src/Symfony/Component/Process/Pipes/AbstractPipes.php

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,14 +52,26 @@ public function close(): void
5252

5353
/**
5454
* Returns true if a system call has been interrupted.
55+
*
56+
* stream_select() returns false when the `select` system call is interrupted by an incoming signal.
5557
*/
5658
protected function hasSystemCallBeenInterrupted(): bool
5759
{
5860
$lastError = $this->lastError;
5961
$this->lastError = null;
6062

61-
// stream_select returns false when the `select` system call is interrupted by an incoming signal
62-
return null !== $lastError && false !== stripos($lastError, 'interrupted system call');
63+
if (null === $lastError) {
64+
return false;
65+
}
66+
67+
if (false !== stripos($lastError, 'interrupted system call')) {
68+
return true;
69+
}
70+
71+
// on applications with a different locale than english, the message above is not found because
72+
// it's translated. So we also check for the SOCKET_EINTR constant which is defined under
73+
// Windows and UNIX-like platforms (if available on the platform).
74+
return \defined('SOCKET_EINTR') && str_starts_with($lastError, 'stream_select(): Unable to select ['.\SOCKET_EINTR.']');
6375
}
6476

6577
/**

0 commit comments

Comments
 (0)