PHP Warning: stream_socket_client(): unable to connect to tcp://:80 (php_network_getaddresses: getaddrinfo failed: Name or service not known) in /data/www/admin/PushCommandService/vendor/workerman/workerman/Connection/AsyncTcpConnection.php on line 195
public function connect()
{
if ($this->_status !== self::STATUS_INITIAL && $this->_status !== self::STATUS_CLOSING &&
$this->_status !== self::STATUS_CLOSED) {
return;
}
$this->_status = self::STATUS_CONNECTING;
$this->_connectStartTime = \microtime(true);
if ($this->transport !== 'unix') {
if (!$this->_remotePort) {
$this->_remotePort = $this->transport === 'ssl' ? 443 : 80;
$this->_remoteAddress = $this->_remoteHost.':'.$this->_remotePort;
}
// Open socket connection asynchronously.
if ($this->_contextOption) {
$context = \stream_context_create($this->_contextOption);
$this->_socket = \stream_socket_client("tcp://{$this->_remoteHost}:{$this->_remotePort}",
$errno, $errstr, 0, \STREAM_CLIENT_ASYNC_CONNECT, $context);
} else {
$this->_socket = \stream_socket_client("tcp://{$this->_remoteHost}:{$this->_remotePort}",
$errno, $errstr, 0, \STREAM_CLIENT_ASYNC_CONNECT);
}
} else {
$this->_socket = \stream_socket_client("{$this->transport}://{$this->_remoteAddress}", $errno, $errstr, 0,
\STREAM_CLIENT_ASYNC_CONNECT);
}
// If failed attempt to emit onError callback.
if (!$this->_socket || !\is_resource($this->_socket)) {
$this->emitError(\WORKERMAN_CONNECT_FAIL, $errstr);
if ($this->_status === self::STATUS_CLOSING) {
$this->destroy();
}
if ($this->_status === self::STATUS_CLOSED) {
$this->onConnect = null;
}
return;
}
// Add socket to global event loop waiting connection is successfully established or faild.
Worker::$globalEvent->add($this->_socket, EventInterface::EV_WRITE, array($this, 'checkConnection'));
// For windows.
if(\DIRECTORY_SEPARATOR === '\\') {
Worker::$globalEvent->add($this->_socket, EventInterface::EV_EXCEPT, array($this, 'checkConnection'));
}
}
我的channel server 监听的是172.16.0.177:2206
channel client 连接的也是 172.16.0.177:2206
而且我没有使用80端口
$this->_socket = \stream_socket_client("tcp://{$this->_remoteHost}:{$this->_remotePort}",
$errno, $errstr, 0, \STREAM_CLIENT_ASYNC_CONNECT);
这行为何启动的时候warnning?
unable to connect to tcp://:80
,很明显,域名/ip没有值关键是我没有监听80端口
channel/client 代码呢
//定时ping(心跳)
Channel\Client::$pingInterval = 10;
读的都是配置文件,channel server 启动的时候都是用的这个配置文件
打印下配置看下对不对呗
AsyncTcpConnection的构造器里加的打印信息
public function __construct($remote_address, array $context_option = array())
{
error_log("--------{$remote_address}--------");
======分隔线=====
打印信息如下
--------frame://172.16.0.177:2206--------
是完全跟我的配置对应的
构造器最后拿到的信息
error_log("----{$this->transport}----{$this->_remoteHost}----{$this->_remotePort}----{$this->_remoteAddress}");
----tcp----172.16.0.177----2206----172.16.0.177:2206
从你贴的代码看,如果没传端口号的话,自动用80或443,所以我感觉是你的配置有时候可能读不到,导致ip为空,端口默认用了80?
有可能