php-src
php-src copied to clipboard
posix_get_last_error() and socket_last_error() return errors from a previous request
Description
posix_get_last_error() and socket_last_error() without a socket return an error left by a previous request in the same worker. POSIX_G(last_error) and SOCKETS_G(last_error) are set to 0 in GINIT and aren't reset when a request ends.
php-fpm with pm = static and pm.max_children = 1, so both requests hit one worker:
<?php
if ($_SERVER['QUERY_STRING'] === 'fail') {
posix_kill(2147483647, 0); // no such process
$socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
@socket_connect($socket, '127.0.0.1', 1); // connection refused
} else {
var_dump(posix_get_last_error(), socket_last_error());
}
Request ?fail, then ?check.
Resulted in this output:
int(3)
int(111)
But I expected this output instead:
int(0)
int(0)
I'm opening a PR that resets both in RSHUTDOWN.
PHP Version
PHP 8.7.0-dev (master). The same code is in 8.4, 8.5 and 8.6.
Operating System
Ubuntu 26.04