我使用socket_create()
创建套接字资源,然后我绑定IP
地址由它socket_bind()
,其工作正常;PHP警告:socket_read():无法读取套接字[104]:连接重置对等
但线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);
这段代码作出SMTP在另一侧(端口25)连接到一个主机MX。 也许这是你连接另一端的错误,但是我怎么能检测到对方现在还没有准备好连接。换句话说,我怎样才能找出“由对等方重置连接”?
我编辑我的问题。 – 2014-10-28 16:22:57
socket_last_error()在socket_create()后不显示任何错误。 – 2014-10-28 16:40:40
但是,在执行在给定时间导致警告的表达式之前它会显示错误吗?你应该在发出'socket_read'之前测试你的套接字。如果由'socket_last_error'报告的错误重新创建您的SMTP会话。再次执行整个socket_create部分。 – itsafire 2014-10-28 18:34:58