workerman 接收数据的问题 关闭自动重启

task
use \Workerman\Worker;
use \Workerman\Connection\AsyncTcpConnection;
require_once './Workerman/Autoloader.php';

$task = new Worker();
// 进程启动时异步建立一个到www.baidu.com连接对象,并发送数据获取数据
$task->onWorkerStart = function($task)
{
    $connection_to_baidu = new AsyncTcpConnection('tcp://****:80');
    // 当连接建立成功时,发送http请求数据
    $connection_to_baidu->onConnect = function($connection_to_baidu)
    {
        echo "connect success\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->onError = function($connection_to_baidu, $code, $msg)
    {
        echo "Error code:$code msg:$msg\n";
    };
    $connection_to_baidu->connect();
};

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

这个实例 如果服务端断开 ,这边就自己onClose 了,我想让他onClose的时候自动重连

$connection_to_baidu->onClose = function($connection_to_baidu)
    {
        $connection_to_baidu->connect();
    };

然后输入了 connect success 但是数据没接收到 ($http_buffer没数据)

3370 1 0
1个回答

walkor 打赏

重连需要重新new AsyncTcpConnection对象

  • task 2016-04-23

    意思是他已经关闭了 需要重新new出来么

  • task 2016-04-23

    $connection_to_baidu = new AsyncTcpConnection('tcp://****:80');
    $connection_to_baidu->connect();
    这样写 貌似 不大管用

  • task 2016-04-23

    $task->onWorkerReload();直接这样了 这样写可以 但是重启的时候 有notice

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