Bug #71907 [NEW]: fwrite returns 0 instead of FALSE when feof
| From: | contact at sshilko dot com | Date: | Sun, 27 Mar 2016 15:38:23 +0000 |
| Subject: | Bug #71907 [NEW]: fwrite returns 0 instead of FALSE when feof | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-200160@lists.php.net to get a copy of this message | ||
From: contact at sshilko dot com
Operating system: Ubuntu 14.04.3 LTS
PHP version: 7.0.4
Package: Sockets related
Bug Type: Bug
Bug description:fwrite returns 0 instead of FALSE when feof
Description:
------------
Hi, there is an issue when detecting broken socket connections:
The behavour is different between 7.0.2 and 7.0.4
According to documentation fwrite should
"fwrite() returns the number of bytes written, or FALSE on error."
But it returns 0 (int) instead of FALSE (bool) and generates NOTICE.
Also feof() never works on 7.0.2 (MacOSX) but works on 7.0.4 on Ubuntu
if (feof($fp)) {
echo 'FEOF detected';
}
Test script:
---------------
Open 2 terminals and launch
1# php server.php
2# php client.php
Then press CTRL+C on server.php terminal:
https://gist.github.com/sshilko/443ae40a4d115ca8325b
Expected result:
----------------
Written result bool(FALSE)
Actual result:
--------------
$ php server.php
Dispatching...
RCV: 12325 Message to send...1459092741
RCV: 12325 Message to send...1459092742
RCV: 12325 Message to send...1459092743
RCV: 12325 Message to send...1459092744
RCV: 12325 Message to send...1459092745
^C
$ php client.php
SS result=bool(true)
Written result:int(35)
Written=35
SS result=bool(true)
Written result:int(35)
Written=35
SS result=bool(true)
Written result:int(35)
Written=35
SS result=bool(true)
Written result:int(35)
Written=35
SS result=bool(true)
Written result:int(35)
Written=35
SS result=bool(true)
PHP Notice: fwrite(): send of 35 bytes failed with errno=32 Broken pipe
in /home/ubuntu/client.php on line 18
Written result:int(0)
Array
(
[timed_out] =>
[blocked] =>
[eof] =>
[stream_type] => tcp_socket/ssl
[mode] => r+
[unread_bytes] => 0
[seekable] =>
)
FEOF detectedWritten=0
SS result=bool(true)
PHP Notice: fwrite(): send of 35 bytes failed with errno=32 Broken pipe
in /home/ubuntu/client.php on line 18
Written result:int(0)
Array
(
[timed_out] =>
[blocked] =>
[eof] => 1
[stream_type] => tcp_socket/ssl
[mode] => r+
[unread_bytes] => 0
[seekable] =>
)
FEOF detected^C
--
Edit bug report at https://bugs.php.net/bug.php?id=71907&edit=1
--
Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=71907&r=trysnapshot54
Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=71907&r=trysnapshot55
Try a snapshot (trunk): https://bugs.php.net/fix.php?id=71907&r=trysnapshottrunk
Fixed in SVN: https://bugs.php.net/fix.php?id=71907&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=71907&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=71907&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=71907&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=71907&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=71907&r=support
Expected behavior: https://bugs.php.net/fix.php?id=71907&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=71907&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=71907&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=71907&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=71907&r=php4
Daylight Savings: https://bugs.php.net/fix.php?id=71907&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=71907&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=71907&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=71907&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=71907&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=71907&r=mysqlcfg