[php-src] Issue #10406: feof() behavior change for UNIX based socket resources in PHP 8.2.
| From: | ChadSikorra | Date: | Sat, 21 Jan 2023 19:46:10 +0000 |
| Subject: | [php-src] Issue #10406: feof() behavior change for UNIX based socket resources in PHP 8.2. | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-243514@lists.php.net to get a copy of this message | ||
Issue: https://github.com/php/php-src/issues/10406
Author: ChadSikorra
### 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: https://github.com/FreeDSx/LDAP/pull/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
<?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