Detecting early failure in php fwrite

Earlier today, I noticed that some php fwrite calls were not made, since the target socket was in a mixed state. There were many links in SYN_SENT that didn't seem to return as failures.

What is the best way to detect this and simply disconnect the connection if bit x did not transmit the bit over the wire?

+5
source share
1 answer

I believe what you are looking for stream_set_timeout. Example:

stream_set_timeout($fp, 2);
fwrite($fp, "GET / HTTP/1.0\r\n\r\n");

You can check if a timeout occurs by checking the flow metadata:

$info = stream_get_meta_data($fp);
// $info['timed_out'] == true : time-out has happened
+2
source

All Articles