gpt4 book ai didi

php - 检测 fsockopen() 打开的套接字上的连接中止

转载 作者:可可西里 更新时间:2023-11-01 02:32:16 24 4
gpt4 key购买 nike

我正在使用 fsockopen() 通过 TCP 将数据发送到远程主机:

$s = fsockopen($host, $port);
fwrite($s, $data);
fclose($s);

之后我如何检测连接是否被远程主机关闭(使用 FIN)或中止(使用 RST)?

最佳答案

根据文档socket_last_error()socket_send()对您有帮助:

socket_send() returns the number of bytes sent, or FALSE on error. socket_last_error() returns the last error on the socket  

我相信,PHP 能够检测到连接是否已关闭,但我不确定。

关于php - 检测 fsockopen() 打开的套接字上的连接中止,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9859345/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com