Description
Description
I have been using feof()
as a way to determine if a socket resource is actively open. In hindsight, I should've used is_resource
for this it seems, as looking at notes for that it will return false if the resource is closed. Regardless, in PHP 8.2 the behavior of feof()
changed for UNIX sockets. Unlike TCP based resources, it calling feof
on it now returns true
even while the resource connection is still open. But I don't see anything in the changelog / release notes describing any change in behavior to this method. If this change was intentional, it seems like it should be documented somewhere? However, since the behavior with TCP isn't officially documented, maybe it's an unfortunate wash 🤷
The code where I originally discovered this was while updating a personal project to verify PHP 8.2 compatibility: FreeDSx/LDAP#56, as that CI run shows that PHP 8.2 is the only version where the unix socket behavior is shown (it tests PHP 7.1 - 8.2 testing). I've simplified the behavior in the below script.
Given the following script:
<?php
$socket_path = '/tmp/test.socket';
if (file_exists($socket_path)) {
unlink($socket_path);
}
$socket = stream_socket_server('unix://' . $socket_path);
var_dump('is connected? ' . (!feof($socket) ? 'true' : 'false'));
Resulted in this output (PHP 8.2):
string(19) "is connected? false"
But I expected this output instead (PHP <= 8.1):
string(18) "is connected? true"
The behavior for checking a TCP based socket resource did not change however. It seems to be specific to UNIX based sockets for some reason.
PHP Version
PHP 8.2
Operating System
Ubuntu 22.04.1