swoole is perfectly adapted to thinkphp5. If you need it, you can refer to it and learn to advance to intermediate and advanced levels.
momo
momo 2018-12-10 11:41:34
0
1
1374

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';    });


##3. Because swoole receives The parameters are different from those received in thinkphp, so they need to be converted to ones that can be recognized by thinkphp. Examples of converted POST parameters are as follows:

$_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

momo
momo

分享tp,laravel,swoole等教程,需要加微信:PHPopen888,还可加入微信群,各种大牛都是3-8年PH...

reply all(1)
momo

It’s really 666

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template