Home >PHP Framework >ThinkPHP >This method can make TP5.0 fly on SWOOLE!
The following tutorial column of thinkphp framework will introduce to you how to make TP5.0 fly on SWOOLE. I hope it will be helpful to friends who need it!
TP-SWOOLE
Currently, TP5.1 has officially provided think-swoole2.0, which has a much more elegant level of integration. , but the integration method of 5.0 is indeed a bit tasteless. So I looked at 2.0 and developed an expansion package for 5.0. You can use composer to download it
composer require xaviertony/xavier-swoole
Before development, you need to be familiar with the life cycle of TP5.0, otherwise you will not be able to start.
Since TP mainly runs under Apache or NGINX, it will be released after each operation, while swoole is a permanent memory. Many TP5 classes are implemented by singletons, so it is inevitable to fall into pitfalls, among which the biggest pitfalls are the main ones. It is a request. Since the request is instantiated after startup, if the request force is not deleted, this instance will be used every time in the future, resulting in the inability to access the page normally, because the request instance needs to be deleted first after each request is reached
public static function deletethis() { if (!is_null(self::$instance)) { self::$instance=null; } }
The configuration file of the third-party package must be under application/extra, and the file name is swoole.php
<?php return [ 'host' => '0.0.0.0', // 监听地址 'port' => 9501, // 监听端口 'mode' => '', // 运行模式 默认为SWOOLE_PROCESS 'sock_type' => '', // sock type 默认为SWOOLE_SOCK_TCP 'app_path' => getcwd() . '/application', // 应用地址 如果开启了 'daemonize'=>true 必须设置(使用绝对路径) 'file_monitor' => false, // 是否开启PHP文件更改监控(调试模式下自动开启) 'file_monitor_interval' => 2, // 文件变化监控检测时间间隔(秒) 'file_monitor_path' => [], // 文件监控目录 默认监控application和config目录 // 可以支持swoole的所有配置参数 'pid_file' => getcwd() . '/runtime/swoole.pid', 'log_file' => getcwd() . '/runtime/swoole.log', 'task_worker_num' => 20, //'document_root' => getcwd() . 'public', //'enable_static_handler' => true, 'daemonize' => 1,//守护 'worker_num' => 8, //worker process num 'max_request' => 10000, ];
Start command
php think swoole start
Daemon start
php think swoole start -d
Stop service
php think swoole stop
The above is the detailed content of This method can make TP5.0 fly on SWOOLE!. For more information, please follow other related articles on the PHP Chinese website!