开发者

Detecting early failure in php fwrite

开发者 https://www.devze.com 2022-12-12 12:16 出处:网络
Earlier today I noticed some calls to php fwrite failing as the destination socket was in a mixed state. There were numerous connections stuck in SYN_SENT and were seemingly not coming back as failure

Earlier today I noticed some calls to php fwrite failing as the destination socket was in a mixed state. There were numerous connections stuck in SYN_SENT and were seemingly not coming back as failures.

What is the best way to detect this and simply time out the connect开发者_开发技巧ion if x bits haven't bit transmitted over the wire?


I believe you are looking for stream_set_timeout. An example:

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

You can check whether a time-out happens by checking the meta data of the stream:

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

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号