如何防止fwrite():由peer重置连接

I have cron which is using fwrite function and after cron is running 1 hour it will crash with error:

fwrite(): send of 29 bytes failed with errno=104 Connection reset by peer

on line:

$fw = @fwrite($this->sock, $msg."
");

After this I always close connection by

fclose($this->sock);

It seems that it is something wrong inside PHP core and DNS resolver because after that I have some problems resolve hostnames to ip adrress. In my functionality is also used getmxrr() and gethostbyname() functions. How to prevent this problems?

After some experiments i used more working solution. I replaced fsockopen function with socket_create and socket_connect and its much much better. Function fsockopen sometimes not conneted correctly.

I got answer from PHP community like this: Inside fwrite is part code of streaming and sometimes it could happen. They said that it is impossible to fix it on fwrite because it can change some functionality of other functions which using streaming too. Soo in finaly its property not fault.