The following is the code after successful debugging and configuration. To facilitate everyone's learning and save everyone's research time, it is shared here.
1. Enable httpServer request
You can create a server directory in the thinkphp directory and create an http_server.php in it
2. Do a few things in http_server.php Things
1. Configure static resource files
//配置静态文件 http://www.live-swoole.com:8811/ $http->set( [ 'enable_static_handler' =>true, //true则,底层收到Http请求会先判断document_root路径下是否存在此文件,如果存在会直接发送文件内容给客户端,不再触发onRequest回调 'document_root' => '/var/www/html/thinkphp5/public/static' , //默认静态资源文件存放目录 'worker_num' => 5, ] );
2. Load the thinkphp framework when the swoole process is started
$http->on('WorkerStart',function(swoole_server $serv,$worker_id){ // 定义应用目录 define('APP_PATH', __DIR__ . '/../application/'); // 加载框架里面的文件 require __DIR__ . '/../thinkphp/base.php'; });
$_POST = [];解决swoole对全局变量不会自动注销 if(isset($request->post)){ foreach ($request->post as $k => $v) { $_POST[$k] = $v; } }4. Solve the problem of displaying the path information of the first visit for each routing access
Find the thinkphp/library/think/Request.php file
if (is_null($this->path)) {} in function path and comment or delete the content inside without leaving any action
In function pathinfo if (is_null($this->pathinfo)) {} comment or delete the content inside without moving
End! If you have any questions, please leave a message online to communicate