[SOLVED] fsockopen(), fgets() and unknown EOF
Posted: Mon May 01, 2006 5:54 pm
Hello!
If I open a connection to an SMTP server and send out commands via fwrite() to a handle opened by fsockopen() I can read the results using fgets() on the handle. Good.
This is working fine for reading back a single line in a response but when attempting the following the script just hangs.
My only guess is that the response does not contain an EOF, even though there are clearly only X number of lines returned. I'm at a loss as to how to read all the data here.
On a response that through telnet I saw 5 lines returned I manually wrote code to run fgets() 5 times on the handle and it worked.... when running it for a 6th time the script hangs like before.
I've tried stream_get_contents() and this has the same outcome. Has anybody got any experience of working out how many times fgets() needs to be called? Is it even anything to do with the EOF?
Cheers.
If I open a connection to an SMTP server and send out commands via fwrite() to a handle opened by fsockopen() I can read the results using fgets() on the handle. Good.
This is working fine for reading back a single line in a response but when attempting the following the script just hangs.
Code: Select all
$data = "";
while (!feof($handle))
{
$data .= fgets($handle);
}
echo $data;On a response that through telnet I saw 5 lines returned I manually wrote code to run fgets() 5 times on the handle and it worked.... when running it for a 6th time the script hangs like before.
I've tried stream_get_contents() and this has the same outcome. Has anybody got any experience of working out how many times fgets() needs to be called? Is it even anything to do with the EOF?
Cheers.