|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2016-03-27 15:38 UTC] 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
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Wed Nov 05 08:00:02 2025 UTC |
Also the function suggested in manual (documentation) function fwrite_stream($fp, $string) { for ($written = 0; $written < strlen($string); $written += $fwrite) { $fwrite = fwrite($fp, substr($string, $written)); if ($fwrite === false) { return $written; } } return $written; } may infinite-loop, this is also mentioned in comments, 6 YEARS ago by nate at frickenate dot com ΒΆ but bad example still there