#21485 [Opn->Ver]: feof() doesn't returns true on a socket stream

From: Date: Thu, 09 Jan 2003 03:40:40 +0000
Subject: #21485 [Opn->Ver]: feof() doesn't returns true on a socket stream
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-29529@lists.php.net to get a copy of this message
ID: 21485 Updated by: iliaa@php.net Reported By: bjarne@sourcetech.se -Status: Open +Status: Verified Bug Type: Sockets related -Operating System: Win2K +Operating System: Win2K/Linux PHP Version: 4.3.0 New Comment: It seems that socket_set_blocking($fp,FALSE); results in other peculiar behaviour. When connecting to SMTP server, the server sends some data across the socket right away, usually something identifying the server. $fp = fsockopen("mail_server", 25); var_dump(fgets($fp, 1024)); fclose($fp); returns the server identify string $fp = fsockopen("mail_server", 25); socket_set_blocking($fp,FALSE); var_dump(fgets($fp, 1024)); fclose($fp); returns (false) $fp = fsockopen("mail_server", 25); sleep(1); socket_set_blocking($fp,FALSE); var_dump(fgets($fp, 1024)); fclose($fp); returns identify string. The position of the sleep() call can be after socket_set_blocking() as well. Previous Comments: ------------------------------------------------------------------------ [2003-01-07 06:00:14] bjarne@sourcetech.se The following code doesn't work with php4.3.0 As foef() never returns true it got stuck in the while()-loop... When running the same code in php4.2.3 it works as it should so it seems like a 4.3.0 issue... ( feof() returns true in 4.2.3... ) The scenario consists of the script connecting to a host which immediatly replies with a textstring; "OK", which in turn is printed out... /Regards Bjarne // Open a socket and connects to the host $fp = fsockopen ($myhost, $myport, $errno, $errstr, 30); // check for valid filepointer if (!$fp) { echo "$errstr ($errno)<br>\n"; } else { // sets the socket to non-blocking socket_set_blocking($fp,FALSE); // read data from socket upto EOF in 128 byte chunks while (!feof($fp)) // <= FAILS IN PHP 4.3.0!!!!! { $buffer .= fgets ($fp,128); } // closing socket fclose ($fp); // printing the buffer print "Buffer:" . $buffer; } ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=21485&edit=1

« previous php.bugs (#29529) next »