thinkphp5.1 integration swoole



<?php use think\Container; $myserver = new swoole_http_server('127.0.0.1',8964); $myserver->on('WorkerStart',function(swoole_server $server,$work_id) { define('APP_PATH', __DIR__ . '/../application/'); require __DIR__ . '/../thinkphp/base.php'; //Container::get('app')->run()->send(); }); $myserver->on('request' , Function ($ Request, the Response $) use ($ myserver) {
  # Yes, swoole anonymous function with a lot of style, use local variables to pass to the anonymous function, because we want to perform in the function body
  # $ mysever- > close () to achieve the purpose of access to different URL to refresh the result of each response, if we do not do this, no matter what the access URL, return the effect is the same
print_r ($ Request
-> Server);
   # swoole due to common global variables such as $ _GET, $ _ POST, $ _ SERVER done a package, our best parse them, and joined in the global array
IF (isset ($ request-> Server)) { the foreach ($ request-> Server AS $ K = > $ V) { $ _SERVER [strtolower ($ K)] = $ V; } } IF (isset ($ request-> header)) { the foreach ($ request-> headeras $k=>$v) { $_REQUEST[strtolower($k)] =$v; } } if (isset($request->get)) { foreach($request->get as $k=>$v) { $_GET[strtolower($k)] =$v; } } if (isset($request->post)) { foreach($request->post as $k=>$v) { $_POST[strtolower($k)] =$v; } } Ob_start (); of Think \ Container :: GET ( ' App ' ) -> RUN () -> the send (); # See thinkphp5.1 / your project directory /public/index.php
# In order to ensure the site we want to run request arrives, the load of all application modules, in order to meet the various calls
echo
" --action-- " .request () -> Action () value is PHP_EOL;. #request () -> Action () is completely built thinkphp5.1 method $ Response -> header ( ' Content-type ' , ' text / HTML; charset = UTF-. 8 ' ); $ RES = ob_get_contents (); # acquiring cache data ob_end_clean (); $ Response -> End ($ RES) ; $ myserver -> use Close (); //$response->end("冲!"); }); $myserver->start();

note:

 

Guess you like

Origin www.cnblogs.com/saintdingspage/p/11105399.html