ThinkPHP即将迎来最新版本6.0,针对目前愈来愈流行Swoole,thinkphp也推出了最新的扩展think-swoole 3.0
因为目前thinkphp 6.0没有稳定版本,因此只能安装开发板php
composer create-project topthink/think tp 6.0.*-dev
接下来安装think-swoole 3.0,目前最新的稳定版本是3.0.2react
composer require topthink/think-swoole
安装结束能够根据本身的需求对配置信息进行修改。TP6的配置信息都存在于外部的config目录,这里主要介绍swoole相关配置信息web
use think\swoole\websocket\room\TableRoom; use think\swoole\websocket\socketio\Handler; use think\swoole\websocket\socketio\Parser; return [ 'server' => [ 'host' => '0.0.0.0', // 监听地址 'port' => 80, // 监听端口 'mode' => SWOOLE_PROCESS, // 运行模式 默认为SWOOLE_PROCESS 'sock_type' => SWOOLE_SOCK_TCP, // sock type 默认为SWOOLE_SOCK_TCP 'options' => [ 'pid_file' => runtime_path() . 'swoole.pid',//主进程ID保存文件路径 'log_file' => runtime_path() . 'swoole.log',//swoole日志文件 'daemonize' => false, // Normally this value should be 1~4 times larger according to your cpu cores. 'reactor_num' => swoole_cpu_num(),//线程数,默认值便可,不设置也能够 'worker_num' => swoole_cpu_num(),//worker进程数量 'task_worker_num' => swoole_cpu_num(),//异步任务进程数量 'enable_static_handler' => true,//是否启用静态服务,若是开启,则优先判断指定的web目录下是否存在请求的静态文件,若是存在,则直接返回 'document_root' => root_path('public'),//web目录 'package_max_length' => 20 * 1024 * 1024, 'buffer_output_size' => 10 * 1024 * 1024, 'socket_buffer_size' => 128 * 1024 * 1024, 'max_request' => 3000, 'send_yield' => true, ], ], 'websocket' => [ 'enabled' => false,//是否开启 'handler' => Handler::class,//处理请求的类,能够自定义 'parser' => Parser::class,//处理解析的类,能够自定义 'route_file' => base_path() . 'websocket.php',//websocket路由文件 'ping_interval' => 25000, 'ping_timeout' => 60000, 'room' => [ 'type' => TableRoom::class, 'room_rows' => 4096, 'room_size' => 2048, 'client_rows' => 8192, 'client_size' => 2048, ], ], 'auto_reload' => false, 'enable_coroutine' => true, 'resetters' => [], 'tables' => [], ];
php think swoole
执行上述命令则能够启动web服务thinkphp
若是须要使用守护进程方式运行,能够配置websocket
'options' => [ 'daemonize' => true ]
支持的命令swoole
php think swoole [start|stop|reload|restart]