官方例子怎么不行呢

<?php
class Server
{

private $serv;

public function __construct() {
    $this->serv = new swoole_server("0.0.0.0", 9501);
    $this->serv->set(array(
        'worker_num' => 8,
        'daemonize' => false,
    ));

    $this->serv->on('Start', 'onStart');
    $this->serv->on('Connect',  'onConnect');
    $this->serv->on('Receive',  'onReceive');
    $this->serv->on('Close', 'onClose');

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

public function onStart( $serv ) {
    echo "Start";
}

public function onConnect( $serv, $fd, $from_id ) {
    $serv->send( $fd, "Hello {$fd}!" );
}

public function onReceive( swoole_server $serv, $fd, $from_id, $data ) {
    echo "Get Message From Client {$fd}:{$data}";
    $serv->send($fd, $data);
}

public function onClose( $serv, $fd, $from_id ) {
    echo "Client {$fd} close connection";
}

}
// 启动服务器 Start the server
$server = new Server();

[root@iZwz96o0ziwb6z9x30b2oiZ jiahuatest]# php server.php
PHP Fatal error: Uncaught TypeError: Argument 2 passed to SwooleServer::on() must be callable, string given in /jiahuatest/server.php:13
Stack trace:

0 /jiahuatest/server.php(13): SwooleServer->on('Start', 'onStart')

1 /jiahuatest/server.php(39): Server->__construct()

2 {main}

thrown in /jiahuatest/server.php on line 13

Fatal error: Uncaught TypeError: Argument 2 passed to SwooleServer::on() must be callable, string given in /jiahuatest/server.php:13
Stack trace:

0 /jiahuatest/server.php(13): SwooleServer->on('Start', 'onStart')

1 /jiahuatest/server.php(39): Server->__construct()

2 {main}

thrown in /jiahuatest/server.php on line 13

阅读 904
评论
    1 个回答
    • 1.1k

    Server启动了你要启动client去连接啊- -。
    这个Server启动以后会输出Start,你输出了吗?

      撰写回答

      登录后参与交流、获取后续更新提醒

      相似问题
      推荐文章