【发布时间】:2014-12-24 03:19:57
【问题描述】:
我使用socket_create()创建套接字资源,然后我通过socket_bind()将IP地址绑定到它,它工作正常;
但在socket_read($sock, 2048) 行一段时间后(超过30分钟)抛出此错误:
"PHP Warning: socket_read(): unable to read from socket [104]: Connection reset by peer in test.php on line 198"。
这是我的简化代码:
$this->sock = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
// check if tcp socket ceated or not
if ($this->sock === false) {
$errorcode = socket_last_error();
$errormsg = socket_strerror($errorcode);
die("Couldn't create socket: [$errorcode] $errormsg");
}
// Bind the source address
socket_bind($this->sock, $this->ip);
// Connect to destination address
socket_connect($this->sock, $this->mxHost, $this->port);
$buf = socket_read($this->sock, 2048);
这段代码与另一端的 MX 主机建立了 SMTP(端口 25)连接。 也许是你的连接另一端的问题,但我怎么能检测到另一端现在还没有准备好连接。换句话说,我怎样才能发现“对等连接重置”发生了?
【问题讨论】:
标签: php sockets telnet php-5.4