<?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
相同的代码,在Windows,PHP7.1.10下,开启php_event.dll、php_sockets.dll,后出现死循环(反复触发连接成功事件)。
报错信息乱码了,看看能不能解决下乱码,看下具体错误信息。
没有具体错误信息不好判断问题
问题已经找到,已经在github主干修复。
请到https://github.com/walkor/Workerman重新下载
测试后还是有问题。
Windows平台 PHP7.1.10
服务器网路有问题,通过域名获取不到百度的ip
相同的网路,不使用SSL就不会报错
会不会是Windows平台的BUG
补充下错误信息
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
有设置重连延时参数,不过不生效,程序陷入死循环。
这两句看不出什么问题哈
重新抓了日志,看看能不能提供帮助。
重新抓了日志,看看能不能提供帮助。
一样的问题,你的服务器网络有点问题,通过域名无法获取主机
我是为了模拟断线,把网卡禁用重启了。重启后网络正常还是报错
自己在workerman源码里打印下日志排查下吧。报错行数都有提示的。
我这里测试关闭网络又开启是没问题的。
@1:请问一下,你的运行环境是什么?
mac
@1:PHP版本 还有 使用了啥扩展?
PHP 7.1.8
event扩展
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]