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

From: Date: Mon, 27 Jan 2003 09:42:47 +0000
Subject: #21485 [NoF->Opn]: feof() doesn't returns true on a socket stream
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-31322@lists.php.net to get a copy of this message
 ID:               21485
 User updated by:  bjarne@sourcetech.se
 Reported By:      bjarne@sourcetech.se
-Status:           No Feedback
+Status:           Open
 Bug Type:         Sockets related
 Operating System: Win2K/Linux
 PHP Version:      4.3.0
 Assigned To:      wez
 New Comment:

Sorry for my late respons, i didnt know u were waiting for input...

I think the reason your example works is because the smtp-server closes
the socket after the "QUIT" -command.

Try to "misspell" it and see what happens...(i.e 'QUIIT')
You get a "unrecognized command" response from the server, but the
important thing is that the smtp-server doesnt close the socket.
The while-loop will now continue to loop until "maximum execution time"
(30 secs in my case)
The feof() -never- returns true in php 4.3.0 but does so in 4.2.3.


And this is exacly my problem.
(In my "real" case I dont connect to a smtp-server but the scenario is
the same.)

Regards
/Bjarne


Previous Comments:
------------------------------------------------------------------------

[2003-01-25 01:00:03] php-bugs@lists.php.net

No feedback was provided for this bug for over 2 weeks, so it is
being suspended automatically. If you are able to provide the
information that was originally requested, please do so and change
the status of the bug back to "Open".

------------------------------------------------------------------------

[2003-01-09 04:33:57] nicos@php.net

The following works for me:

$fp = fsockopen("localhost", 25);
stream_set_blocking($fp, false);
fwrite($fp, "QUIT\r\n");
while(!feof($fp)) {
  $data = fgets($fp);
  var_dump($data);
}
echo "\nAll done\n";

Under Win2000, WinXP, Linux2.4.19 (with IPv6), FreeBSD4.5 (with
IPv6)...

Not verified at all for me.

------------------------------------------------------------------------

[2003-01-09 04:23:45] wez@php.net

The following works for me:

$fp = fsockopen("localhost", 25);
stream_set_blocking($fp, false);
fwrite($fp, "QUIT\r\n");
while(!feof($fp)) {
  $data = fgets($fp);
  var_dump($data);
}
echo "\nAll done\n";

Remember that feof() will only return true when there is no more data
in the internal buffer held by the stream, so you need to drain off any
input by consuming it all first.

------------------------------------------------------------------------

[2003-01-09 04:05:25] wez@php.net

The nature of non-blocking sockets means that your script must always
be prepared to handle a false or zero length return from fgets/fread,
so I'm not worried about that aspect.
However, the feof() does seem to be a problem.
Looking into it...

------------------------------------------------------------------------

[2003-01-09 02:48:19] bjarne@sourcetech.se

I've noticed that I need the sleep() in order to retrieve the data.

The behaviour with blocking/non blocking sockets haven't changed
though, its still the same in php 4.3.0 as it were in previous php
versions.

What has changed is the feof() that never return true.

Regards
/Bjarne

------------------------------------------------------------------------

The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at
    http://bugs.php.net/21485

-- 
Edit this bug report at http://bugs.php.net/?id=21485&edit=1



Thread (8 messages)

« previous php.bugs (#31322) next »