fwrite/fread : Connection reset by peer

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
bobhq
Forum Newbie
Posts: 2
Joined: Tue Dec 23, 2008 8:39 am

fwrite/fread : Connection reset by peer

Post 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.
User avatar
Syntac
Forum Contributor
Posts: 327
Joined: Sun Sep 14, 2008 7:59 pm

Re: fwrite/fread : Connection reset by peer

Post by Syntac »

Are you trying to access a remote file?
bobhq
Forum Newbie
Posts: 2
Joined: Tue Dec 23, 2008 8:39 am

Re: fwrite/fread : Connection reset by peer

Post 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
Post Reply