1、環境說明
阿里雲CentOS 7.4
推薦(免費):swoole
# #2、開發
1.在tp根目錄下新建一個server目錄,用來存放swool_http_server。http_server.php 程式碼程式碼
<?php /** * Created by PhpStorm. * Date: 2018/7/22 * Time: 15:12 */ $http = new swoole_http_server('0.0.0.0', 8811); //set函数用于设置swoole_server运行时的各项参数 $http->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 执行应用并响应 think\Container::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
##沒有報錯,啟動成功。 ######3. 在index 新建一個測試方法,存取伺服器8811連接埠###########################3、問題# ########.swoole 不會登出$_GET $_POST .... 超全域變數###
以上是介紹swoole http_server 適配 thinkphp 5.1的詳細內容。更多資訊請關注PHP中文網其他相關文章!