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 監(jiān)聽(tīng)的是172.16.0.177:2206
channel client 連接的也是 172.16.0.177:2206
而且我沒(méi)有使用80端口
$this->_socket = \stream_socket_client("tcp://{$this->_remoteHost}:{$this->_remotePort}",
$errno, $errstr, 0, \STREAM_CLIENT_ASYNC_CONNECT);
這行為何啟動(dòng)的時(shí)候warnning?
unable to connect to tcp://:80
,很明顯,域名/ip沒(méi)有值
//定時(shí)ping(心跳)
Channel\Client::$pingInterval = 10;
//連接到channel服務(wù)器
Channel\Client::connect($this->configInfo['channel_server']['host'], $this->configInfo['channel_server']['port']);
Channel\Client::$onConnect = function () {
echo "{$this->nodeName}已經(jīng)連接上channel server" . PHP_EOL;
};
Channel\Client::$onMessage = function ($eventName, $eventData) {
echo "{$this->nodeName}接收到channel server事件:{$eventName},內(nèi)容:{$eventData}" . PHP_EOL;
};
Channel\Client::$onClose = function () {
echo "{$this->nodeName}已經(jīng)與channel server失去連接" . PHP_EOL;
}
AsyncTcpConnection的構(gòu)造器里加的打印信息
public function __construct($remote_address, array $context_option = array())
{
error_log("--------{$remote_address}--------");
======分隔線=====
打印信息如下
--------frame://172.16.0.177:2206--------
是完全跟我的配置對(duì)應(yīng)的
構(gòu)造器最后拿到的信息
error_log("----{$this->transport}----{$this->_remoteHost}----{$this->_remotePort}----{$this->_remoteAddress}");
----tcp----172.16.0.177----2206----172.16.0.177:2206
$this->_remotePort = $this->transport === 'ssl' ? 443 : 80;
從你貼的代碼看,如果沒(méi)傳端口號(hào)的話,自動(dòng)用80或443,所以我感覺(jué)是你的配置有時(shí)候可能讀不到,導(dǎo)致ip為空,端口默認(rèn)用了80?