Page 1 of 1

fwrite/fread : Connection reset by peer

Posted: Tue Dec 23, 2008 8:51 am
by bobhq
Hi, I'm a bit of a newbie so apologies if this is very basic, I've searched for hours with no luck.

I have the following code that runs in a loop:

Code: Select all

fwrite($fp, $string."\r\n");
if (strpos(fread($fp, 128), $searchstring)) {
    Do Something;
}
This runs fine, however the $searchstring I am looking for will occur in the first 40 bytes of the read string so I only really want to read the first 40 bytes. If I set the bytes to 40 the script runs for a few minutes and I then get:

Code: Select all

PHP Notice:  fwrite(): send of 15 bytes failed with errno=104 Connection reset by peer
This error doesn't occur if the bytes are set to a figure higher than the actual string length (such as 128)

What is causing this error please and how can I stop it occurring.

Thanks, Bob.

Re: fwrite/fread : Connection reset by peer

Posted: Tue Dec 23, 2008 9:53 pm
by Syntac
Are you trying to access a remote file?

Re: fwrite/fread : Connection reset by peer

Posted: Wed Dec 24, 2008 4:06 am
by bobhq
Sorry should have said. I am connecting to another server which responds to the fwrite that I send.

The error is directly related to the amount of the servers response I fread. If I fread part of the servers response the error occurs after a few minutes, if I fread all the response the error never occurs.

I'm guessing that the other server may be timeing out waiting for me to read the rest of the string, but that's a total guess?

Thaks, Bob