<?php
namespace app\http;
use think\swoole\Server;
class Swoole extends Server
{
protected $host = '0.0.0.0';
protected $port = 9501;
protected $serverType = 'socket';
protected $mode = SWOOLE_PROCESS;
protected $sockType = SWOOLE_SOCK_TCP;
protected $option = [
'worker_num'=> 4,
'max_request' => 10000,
'daemonize' => false,
'backlog' => 128
];
public function onMessage($server, $frame) {
echo "receive from {$frame->fd}:{$frame->data},opcode:{$frame->opcode},fin:{$frame->finish}\n";
$server->push($frame->fd, "this is server");
}
public function onReceive($server, $fd, $from_id, $data)
{
$server->send($fd, 'Swoole: '.$data);
}
public function onClose($ser, $fd) {
echo "client {$fd} closed\n";
}
}按照手册自定义了swoole服务类,也配置了'swoole_class' => 'app\http\Swoole',启动服务后能连但onReceive没有接收到数据也没有返回信息 最佳答案