swoole / swoole-src

🚀 Coroutine-based concurrency library for PHP
https://www.swoole.com
Apache License 2.0
18.48k stars 3.16k forks source link

php7 + 1.7.21 ontask出错 #417

Closed zzjin closed 9 years ago

zzjin commented 9 years ago

RT.测试如果swoole_server下,ontask传递一个array.会报错 测试server代码:

<?php
class SwooleServer{
    private $serv;

    public function __construct() {
        global $_config;
        $this -> serv = new swoole_server('127.0.0.1', 9999);
        $this -> serv -> set([
            'worker_num' => 4,
            'max_request' => 50000,

            'task_worker_num' => 4,
            'task_max_request' => 50000,

            'open_eof_check' => true, //打开EOF检测
            'package_eof' => "\r\n", //设置EOF
            //1.7.17版本会有问题,还是别用
            'open_eof_split' => true, //底层拆分eof的包

            'dispatch_mode' => 3,
            // 'daemonize' => true,
            // 'log_file' => __DIR__.'/Logs/swoole.log'
        ]);

        $this -> serv -> on('Receive', [$this, 'onReceive']);
        $this -> serv -> on('Close', [$this, 'onClose']);

        // bind callback
        $this -> serv -> on('Task', array($this, 'onTask'));
        $this -> serv -> on('Finish', array($this, 'onFinish'));

        $this -> serv -> start();
    }

    public function onReceive(swoole_server $serv, $fd, $from_id, $data) {
        $datas = trim($data);
        $datas = explode($serv->setting['package_eof'], $datas);
        $task_data = ['fd' => $fd, 'args' => $datas];
        $serv -> task($task_data);
    }

    public function onTask(swoole_server $serv, $task_id, $from_id, $data) {
        return ['fd' => $data['fd'], 'data' => $data];
    }

    public function onFinish(swoole_server $serv, $task_id, $data) {
        var_dump($data);
        $serv -> send($data['fd'], json_encode($data));
    }

    public function onClose(swoole_server $server, int $fd, int $from_id) {}
}

$server = new SwooleServer();

报错信息:

PHP Fatal error:  Uncaught Error: Cannot use object of type swoole_server as array in /root/swoole_test.php:43
Stack trace:
#0 [internal function]: SwooleServer->onTask(Object(swoole_server), 0, 0, Object(swoole_server))
#1 /root/swoole_test.php(32): swoole_server->start()
#2 /root/swoole_test.php(54): SwooleServer->__construct()
#3 {main}
  thrown in /root/swoole_test.php on line 43
zzjin commented 9 years ago

UPDATE: 编译了最新的master之后,还是上面的测试代码还是会报错误: [2015-12-04 22:08:46 $23530.0] WARN swManager_check_exit_status: worker#2 abnormal exit, status=0, signal=11 然后task进程会退出

目前调试到的结果是在函数swWorker_send2worker中,send操作会失败