异步TCP,使用SSL断线重连时报错

977945676
<?php
use \Workerman\Worker;
use \Workerman\Connection\AsyncTcpConnection;

require_once __DIR__ . '/Workerman/Autoloader.php';

$task = new Worker();
// 进程启动时异步建立一个到www.baidu.com连接对象,并发送数据获取数据
$task->onWorkerStart = function($task)
{
    //不使用SSL,断线重连正常
    $connection_to_baidu = new AsyncTcpConnection('tcp://www.baidu.com:443');

    // 设置为ssl加密连接
    $connection_to_baidu->transport = 'ssl';

    $connection_to_baidu->onConnect = function($connection_to_baidu)
    {
        echo "connect success\n";
        $connection_to_baidu->send("GET / HTTP/1.1\r\nHost: www.baidu.com\r\nConnection: keep-alive\r\n\r\n");
    };
    $connection_to_baidu->onMessage = function($connection_to_baidu, $http_buffer)
    {
        //echo $http_buffer;
    };
    $connection_to_baidu->onClose = function($connection_to_baidu)
    {
        echo "connection closed\n";
        $connection_to_baidu->reConnect(5);
    };
    $connection_to_baidu->onError = function($connection_to_baidu, $code, $msg)
    {
        echo "Error code:$code msg:$msg\n";
    };
    $connection_to_baidu->connect();
};

// 运行worker
Worker::runAll();

非SSL可正常实现断线自动重连。使用SSL提示一下错误:

Warning: stream_socket_client(): unable to connect to ssl://14.215.177.38:443 (Unknown error) in .\Workerman\Connection\AsyncTcpConnection.php o
n line 173

Call Stack:
    0.4127     357632   1. {main}() .\http.php:0
    0.4144     472024   2. Workerman\Worker::runAll() .\http.php:38
    0.4174     535304   3. Workerman\Worker::runAllWorkers() .\Workerman\Worker.php:382
    0.4174     535304   4. Workerman\Worker->run() .\Workerman\Worker.php:473
    0.6719     689440   5. Workerman\Events\Select->loop() .\Workerman\Worker.php:856
  236.0120     689240   6. Workerman\Events\Select->tick() .\Workerman\Events\Select.php:274
  236.0121     689240   7. call_user_func_array:{.\Workerman\Events\Select.php:233}() .\Workerman\Events\Sel
ect.php:233
  236.0121     689304   8. Workerman\Connection\AsyncTcpConnection->connect() .\Workerman\Events\Select.php:233
  236.0121     689400   9. stream_socket_client() .\Workerman\Connection\AsyncTcpConnection.php:173

Error code:1 msg:
connection closed
PHP Warning:  stream_socket_client(): SSL: �����׽���û�����Ӳ���(��ʹ��һ�� sendto ���÷������ݱ��׽���ʱ)û���ṩ��ַ�����ͻ�������ݵ�����û�б����ܡ�
 in .\Workerman\Connection\AsyncTcpConnection.php on line 173
PHP Stack trace:
PHP   1. {main}() .\http.php:0
PHP   2. Workerman\Worker::runAll() .\http.php:38
PHP   3. Workerman\Worker::runAllWorkers() .\Workerman\Worker.php:382
PHP   4. Workerman\Worker->run() .\Workerman\Worker.php:473
PHP   5. Workerman\Events\Select->loop() .\Workerman\Worker.php:856
PHP   6. Workerman\Events\Select->tick() .\Workerman\Events\Select.php:274
PHP   7. call_user_func_array:{.\Workerman\Events\Select.php:233}() .\Workerman\Events\Select.php:233
PHP   8. Workerman\Connection\AsyncTcpConnection->connect() .\Workerman\Events\Select.php:233
PHP   9. stream_socket_client() .\Workerman\Connection\AsyncTcpConnection.php:173
4924 9 0
9个回答

977945676

相同的代码,在Windows,PHP7.1.10下,开启php_event.dll、php_sockets.dll,后出现死循环(反复触发连接成功事件)。

  • 暂无评论
walkor 打赏

报错信息乱码了,看看能不能解决下乱码,看下具体错误信息。
没有具体错误信息不好判断问题

  • 暂无评论
walkor 打赏

问题已经找到,已经在github主干修复。
请到https://github.com/walkor/Workerman重新下载

977945676
connection closed
PHP Warning:  stream_socket_client(): php_network_getaddresses: getaddrinfo failed: ֪  in .\Workerman\Connection\AsyncTcpConnection.php on line 181
PHP Stack trace:
PHP   1. {main}() .\http.php:0
PHP   2. Workerman\Worker::runAll() .\http.php:44
PHP   3. Workerman\Worker::runAllWorkers() .\Workerman\Worker.php:382
PHP   4. Workerman\Worker->run() .\Workerman\Worker.php:473
PHP   5. Workerman\Events\Select->loop() .\Workerman\Worker.php:856
PHP   6. Workerman\Events\Select->tick() .\Workerman\Events\Select.php:274
PHP   7. call_user_func_array:{.\Workerman\Events\Select.php:233}() .\Workerman\Events\Select.php:233
PHP   8. Workerman\Connection\AsyncTcpConnection->connect() .\Workerman\Events\Select.php:233
PHP   9. stream_socket_client() .\Workerman\Connection\AsyncTcpConnection.php:181

Warning: stream_socket_client(): php_network_getaddresses: getaddrinfo failed: ֪  in .\Workerman\Connection\AsyncTcpConnection.php on line 181

Call Stack:
    0.4161     357520   1. {main}() .\http.php:0
    0.4176     471776   2. Workerman\Worker::runAll() .\http.php:44
    0.4209     535016   3. Workerman\Worker::runAllWorkers() .\Workerman\Worker.php:382
    0.4209     535016   4. Workerman\Worker->run() .\Workerman\Worker.php:473
    0.6775     689344   5. Workerman\Events\Select->loop() .\Workerman\Worker.php:856
   20.5527     689144   6. Workerman\Events\Select->tick() .\Workerman\Events\Select.php:274
   20.5529     689144   7. call_user_func_array:{.\Workerman\Events\Select.php:233}() .\Workerman\Events\Select.php:233
   20.5529     689208   8. Workerman\Connection\AsyncTcpConnection->connect() .\Workerman\Events\Select.php:233
   20.5529     689304   9. stream_socket_client() .\Workerman\Connection\AsyncTcpConnection.php:181

PHP Warning:  stream_socket_client(): unable to connect to ssl://www.baidu.com:443 (php_network_getaddresses: getaddrinfo failed: ֪ ) in .\Workerman\Connection\AsyncTcpConnection.php o
n line 181
PHP Stack trace:
PHP   1. {main}() .\http.php:0
PHP   2. Workerman\Worker::runAll() .\http.php:44
PHP   3. Workerman\Worker::runAllWorkers() .\Workerman\Worker.php:382
PHP   4. Workerman\Worker->run() .\Workerman\Worker.php:473
PHP   5. Workerman\Events\Select->loop() .\Workerman\Worker.php:856
PHP   6. Workerman\Events\Select->tick() .\Workerman\Events\Select.php:274
PHP   7. call_user_func_array:{.\Workerman\Events\Select.php:233}() .\Workerman\Events\Select.php:233
PHP   8. Workerman\Connection\AsyncTcpConnection->connect() .\Workerman\Events\Select.php:233
PHP   9. stream_socket_client() .\Workerman\Connection\AsyncTcpConnection.php:181

Warning: stream_socket_client(): unable to connect to ssl://www.baidu.com:443 (php_network_getaddresses: getaddrinfo failed: ֪ ) in .\Workerman\Connection\AsyncTcpConnection.php on lin
e 181

Call Stack:
    0.4161     357520   1. {main}() .\http.php:0
    0.4176     471776   2. Workerman\Worker::runAll() .\http.php:44
    0.4209     535016   3. Workerman\Worker::runAllWorkers() .\Workerman\Worker.php:382
    0.4209     535016   4. Workerman\Worker->run() .\Workerman\Worker.php:473
    0.6775     689344   5. Workerman\Events\Select->loop() .\Workerman\Worker.php:856
   20.5527     689144   6. Workerman\Events\Select->tick() .\Workerman\Events\Select.php:274
   20.5529     689144   7. call_user_func_array:{.\Workerman\Events\Select.php:233}() .\Workerman\Events\Select.php:233
   20.5529     689208   8. Workerman\Connection\AsyncTcpConnection->connect() .\Workerman\Events\Select.php:233
   20.5529     689304   9. stream_socket_client() .\Workerman\Connection\AsyncTcpConnection.php:181

Error code:1 msg:php_network_getaddresses: getaddrinfo failed: ֪
connection closed
PHP Warning:  stream_socket_client(): php_network_getaddresses: getaddrinfo failed: ֪  in .\Workerman\Connection\AsyncTcpConnection.php on line 181
PHP Stack trace:
PHP   1. {main}() .\http.php:0
PHP   2. Workerman\Worker::runAll() .\http.php:44
PHP   3. Workerman\Worker::runAllWorkers() .\Workerman\Worker.php:382
PHP   4. Workerman\Worker->run() .\Workerman\Worker.php:473
PHP   5. Workerman\Events\Select->loop() .\Workerman\Worker.php:856
PHP   6. Workerman\Events\Select->tick() .\Workerman\Events\Select.php:274
PHP   7. call_user_func_array:{.\Workerman\Events\Select.php:233}() .\Workerman\Events\Select.php:233
PHP   8. Workerman\Connection\AsyncTcpConnection->connect() .\Workerman\Events\Select.php:233
PHP   9. stream_socket_client() .\Workerman\Connection\AsyncTcpConnection.php:181

Windows平台 PHP7.1.10

bcmath
bz2
calendar
Core
ctype
curl
date
dom
filter
gd
hash
iconv
json
libxml
mbstring
mcrypt
mysqli
mysqlnd
openssl
pcre
PDO
pdo_mysql
pdo_sqlite
Phar
readline
Reflection
session
shmop
SimpleXML
sockets
SPL
sqlite3
standard
tokenizer
wddx
xdebug
xml
xmlreader
xmlwriter
xsl
zip
zlib

Xdebug
  • 暂无评论
walkor 打赏

unable to connect to ssl://www.baidu.com:443 (php_network_getaddresses: getaddrinfo failed:

服务器网路有问题,通过域名获取不到百度的ip

977945676

PHP Warning: stream_socket_client(): Failed to enable crypto in .\Workerman\Connection\AsyncTcpConnection.php on line 181

PHP Warning: stream_socket_client(): unable to connect to ssl://www.baidu.com:443 (Unknown error) in .\Workerman\Connection\AsyncTcpConnection.php o
n line 181

有设置重连延时参数,不过不生效,程序陷入死循环。

  • 暂无评论
walkor 打赏

这两句看不出什么问题哈

  • 977945676 2017-10-12

    重新抓了日志,看看能不能提供帮助。

977945676

重新抓了日志,看看能不能提供帮助。

  • 暂无评论
walkor 打赏

stream_socket_client(): unable to connect to ssl://www.zhihu.com:443 (php_network_getaddresses: getaddrinfo failed: 不知道这样的主机。 ) in .\Workerman\Connection\AsyncTcpConnection.php on line 181

一样的问题,你的服务器网络有点问题,通过域名无法获取主机

  • 977945676 2017-10-12

    我是为了模拟断线,把网卡禁用重启了。重启后网络正常还是报错

  • walkor 2017-10-12

    自己在workerman源码里打印下日志排查下吧。报错行数都有提示的。
    我这里测试关闭网络又开启是没问题的。

  • 977945676 2017-10-12

    @1:请问一下,你的运行环境是什么?

  • walkor 2017-10-12

    mac

  • 977945676 2017-10-12

    @1:PHP版本 还有 使用了啥扩展?

  • walkor 2017-10-12

    PHP 7.1.8
    event扩展

  • walkor 2017-10-12

    php -m
    [PHP Modules]
    bcmath
    bz2
    calendar
    Core
    ctype
    curl
    date
    dba
    dom
    event
    exif
    fileinfo
    filter
    ftp
    gd
    gettext
    hash
    iconv
    igbinary
    json
    ldap
    libxml
    mbstring
    memcached
    mysqli
    mysqlnd
    odbc
    openssl
    pcntl
    pcre
    PDO
    pdo_mysql
    PDO_ODBC
    pdo_sqlite
    Phar
    posix
    readline
    Reflection
    session
    shmop
    SimpleXML
    soap
    sockets
    SPL
    sqlite3
    standard
    sysvmsg
    sysvsem
    sysvshm
    tokenizer
    wddx
    xml
    xmlreader
    xmlrpc
    xmlwriter
    xsl
    zip
    zlib

    [Zend Modules]

年代过于久远,无法发表回答
×
🔝