Bug #79060 [Fbk->Csd]: fgets errno=22

From: Date: Fri, 03 Jan 2020 15:50:45 +0000
Subject: Bug #79060 [Fbk->Csd]: fgets errno=22
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-224692@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 User updated by: namiltd at yahoo dot com Reported by: namiltd at yahoo dot com Summary: fgets errno=22 -Status: Feedback +Status: Closed Type: Bug Package: *General Issues Operating System: Debian GNU/Linux 9 PHP Version: 7.4.1 Block user comment: N Private report: N New Comment: Everything clear, thank you for the explanation. Previous Comments: ------------------------------------------------------------------------ [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 ------------------------------------------------------------------------ [2020-01-03 13:18:57] namiltd at yahoo dot com Description: ------------ Unexpected notice: Notice: fgets(): read of 8192 bytes failed with errno=22 Invalid argument in /home/www/test.php on line 3 Interestingly, the buffer is 2048 but indicates 8192 Test script: --------------- <?php $file = fopen("/sys/class/net/lo/speed","r"); echo ">".fgets($file, 2048)."<"; fclose($file); ?> Expected result: ---------------- >< Actual result: -------------- Notice: fgets(): read of 8192 bytes failed with errno=22 Invalid argument in /home/www/test.php on line 3 >< ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=79060&edit=1

« previous php.bugs (#224692) next »