<?PHP
/**
* Created by PHPStorm.
* Date: 2019/10/30
* Time: 9:54
*/
namespace app\index\controller;
use think\swoole\Server;
class Swoole extends Server
{
protected $host = '0.0.0.0';
protected $port = 9502;
protected $serverType = 'socket';
protected $option = [
'worker_num'=> 4,
'daemonize' => false,
'backlog' => 128,
];
public function onConnect($serv, $fd)
{
echo "server: handshake success with fd{$fd}\n";
}
public function onRequest($request, $response)
{
}
public function onMessage($server, $frame)
{
$info = db('sys_config')->find();
dump($info);
//定时器
$this->tick(2000, function ($id) use ($server,$frame) {
$server->push($frame->fd, "this is server");
});
}
public function onReceive($server, $fd, $from_id, $data)
{
$server->send($fd, 'Swoole: '.$data);
}
public function onClose($serv, $fd)
{
}
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。