Bug #71907 [Opn]: fwrite returns 0 instead of FALSE when feof
| From: | contact at sshilko dot com | Date: | Sun, 27 Mar 2016 15:40:31 +0000 |
| Subject: | Bug #71907 [Opn]: fwrite returns 0 instead of FALSE when feof | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-200161@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=71907&edit=1
ID: 71907
User updated by: contact at sshilko dot com
Reported by: contact at sshilko dot com
Summary: fwrite returns 0 instead of FALSE when feof
Status: Open
Type: Bug
Package: Sockets related
Operating System: Ubuntu 14.04.3 LTS
PHP Version: 7.0.4
Block user comment: N
Private report: N
New Comment:
Additionnaly stream_get_meta_data()['eof'] != feof()
Previous Comments:
------------------------------------------------------------------------
[2016-03-27 15:38:17] contact at sshilko dot com
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 this bug report at https://bugs.php.net/bug.php?id=71907&edit=1