Bug #79060 [Csd->Nab]: fgets errno=22
| From: | cmb@php.net | Date: | Fri, 03 Jan 2020 17:57:32 +0000 |
| Subject: | Bug #79060 [Csd->Nab]: fgets errno=22 | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-224697@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=79060&edit=1
ID: 79060
Updated by: cmb@php.net
Reported by: namiltd at yahoo dot com
Summary: fgets errno=22
-Status: Closed
+Status: Not a bug
Type: Bug
Package: *General Issues
Operating System: Debian GNU/Linux 9
PHP Version: 7.4.1
Block user comment: N
Private report: N
Previous Comments:
------------------------------------------------------------------------
[2020-01-03 15:50:45] namiltd at yahoo dot com
Everything clear, thank you for the explanation.
------------------------------------------------------------------------
[2020-01-03 15:42:48] nikic@php.net
is_readable() tells you whether you have "r" permissions on the path (which you clearly
do, as the fopen is successful). It does not tell you whether actually reading from the FD will be
successful. (A simple example is a directory -- on Linux these will fopen fine, but fail reading
with errno 21.)
The behavior of /sys files is determined by the kernel and/or device drivers. This particular file
happens to reject reads with errno 22.
That's just how things are. If you try to "cat /sys/class/net/lo/speed" you'll
get exactly the same result.
------------------------------------------------------------------------
[2020-01-03 15:20:45] namiltd at yahoo dot com
But is_readable("/sys/class/net/lo/speed") returns true
Try:
<?php
$fname = "/sys/class/net/lo/speed";
$file = fopen($fname, "r");
if (is_readable($fname)) {
echo ">".fgets($file, 2048)."<";
} else {
echo "File is not readable";
}
fclose($file);
------------------------------------------------------------------------
[2020-01-03 14:43:19] nikic@php.net
What is the bug here? The fgets() fails because the "file" is not readable. Since PHP 7.4,
file system read/write failures result in a notice and false return value (this is noted in the
upgrading notes).
------------------------------------------------------------------------
[2020-01-03 13:24:07] namiltd at yahoo dot com
E-mail change
------------------------------------------------------------------------
The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at
https://bugs.php.net/bug.php?id=79060
--
Edit this bug report at https://bugs.php.net/bug.php?id=79060&edit=1