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

标签 php sockets tcp

我正在使用 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/

相关文章:

php - 获取事件页面的当前类别 ID

php - 获取 PHP 数组中的最后一个数字索引

c - IP和TCP头校验和在c中计算

php - mysql连接和求和问题

php - 在 PHP 函数中获取调用范围?

c - 如何验证 ICMPv6 校验和? (为什么我总是得到 0x3fff 的校验和?)

java - 如何检测客户端何时与服务器断开连接

c - timeout = 0 的 recvmmsg() 等同于非阻塞 recvmsg()?

java - 通过tcp向logstash发送数据

tcp - TCP/IP 是如何报告错误的?