NIUCLOUD是一款SaaS管理后台框架多应用插件+云编译。上千名开发者、服务商正在积极拥抱开发者生态。欢迎开发者们免费入驻。一起助力发展! 广告
~~~ <?php namespace app\service\server; use MiniEnjoy\core\Loger; use MiniEnjoy\shop\order\OrderCancel; use MiniEnjoy\util\DateTimeHelper; use think\console\Command; use think\console\Input; use think\console\Output; use think\Db; use think\db\Where; class OrderServer extends Command{ protected $server; protected function configure() { $this->setName('OrderServer:start')->setDescription('Start OrderServer!'); } protected function execute(Input $input, Output $output) { // \swoole\Timer::tick(1000, function(){ // echo "timeout\n"; // }); $server = new \swoole_server("127.0.0.1", 9501, SWOOLE_BASE, SWOOLE_SOCK_TCP); $server->on('connect', function ($server, $fd){ echo "connection open: {$fd}\n"; }); $server->on('receive', function ($server, $fd, $reactor_id, $data) { echo $data; // swoole_timer_after(1000*5, function(){ // echo 'after time 5000'; // }); $server->send($fd, "Raymond Swoole: {$data}"); $server->close($fd); }); $server->on('close', function ($server, $fd) { echo "connection close: {$fd}\n"; }); $server->on("start", function (\swoole_server $server){ echo "定时器任务开启\n"; $timer = new \think\swoole\Timer(); $timer->tick(1000,function (){ }); // echo "On master end."; }); $server->start(); } } ~~~