fgets hangs on a socket
| From: | Tyson Lloyd Thwaites | Date: | Fri, 13 Oct 2000 07:04:16 +0000 |
| Subject: | fgets hangs on a socket | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-19955@lists.php.net to get a copy of this message | ||
Hi all,
This is driving me crazy. I have seen all the posts regarding this
matter but I don't see a solution.
The problem is that fgets or feof doesn't seem to be able to detect
the end of the data. It hangs on what I suspect is a multiple of 128.
If I change 128 to 2, I get the whole file, but it hangs after the last
character.
PLEASE: how do I tell this thing to stop reading from the socket? I
am guessing that webservers do not send eofs on the end of the
HTTP data, so I am looking for another way to see that there is no
more data on the socket.
THANKS HEAPS for any help, PHP legends.
//-----------------------------------------------------------------------
// Open the connection
$fp = fsockopen('203.58.190.226', 80, &$err_num, &$err_msg, 30);
if ($fp) {
// Send everything
fputs($fp, $header . $request);
// Get the response
while (!feof($fp)) {
echo fgets($fp, 128);
}
fclose($fp);
}
//-----------------------------------------------------------------------
Regards,
Tyson Lloyd Thwaites
I.T.&e Ltd