
1、环境说明
thinkphp 5.1swoole 4.0.2
阿里云CentOS 7.4
推荐(免费):swoole
2、开发
立即学习“PHP免费学习笔记(深入)”;
1.在tp根目录下新建一个server目录,用来存放swool_http_server。

http_server.php 代码代码
set([ 'worker_num'=>4 ,//worker process num]);//此事件在Worker进程/Task进程启动时发生$http->on('WorkerStart',function (swoole_server $server, $worker_id){ // 定义应用目录 define('APP_PATH', __DIR__ . '/../application/'); // 加载基础文件 ThinkPHP 引导文件 require __DIR__ . '/../thinkphp/base.php';});$http->on('request', function ($request, $response){ if($request->server){ foreach ($request->server as $key => $val){ $_SERVER[strtoupper($key)] = $val; } } if($request->header){ foreach ($request->header as $key => $val){ $_SERVER[strtoupper($key)] = $val; } } if($request->get){ foreach ($request->get as $key => $val){ $_GET[$key] = $val; } } if($request->post){ foreach ($request->post as $key => $val){ $_POST[$key] = $val; } } ob_start(); try{ // thinkphp 执行应用并响应 thinkContainer::get('app') ->run() ->send(); }catch (Exception $exception){ // todo } $res = ob_get_contents(); ob_end_clean(); $response->end($res);});$http->start();
2. 进入service目录,执行 php http_server.php 启动swoole_http_server
琅琅配音
全能AI配音神器
208 查看详情

没有报错,启动成功。
3. 在index 新建一个测试方法,访问服务器8811端口


3、问题
.swoole 不会注销$_GET $_POST …. 超全局变量
以上就是介绍swoole http_server 适配 thinkphp 5.1的详细内容,更多请关注创想鸟其它相关文章!
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。
如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至 chuangxiangniao@163.com 举报,一经查实,本站将立刻删除。
发布者:程序猿,转转请注明出处:https://www.chuangxiangniao.com/p/232037.html
微信扫一扫
支付宝扫一扫