Tp 5.1+バージョンはSwooleと結合---学習ノート(5)
7084 ワード
http://www.thinkphp.cn/down.html
$http = new swoole_http_server("0.0.0.0", 9501);
$http->set([
'enable_static_handler'=>true,
'document_root' => '/home/wwwroot/default/swool/demo/tp5
/public/static',
//
'worker_num' => 4,
]);
$http->on('WorkerStart', function ($http, $worker_id){
require __DIR__ . '/../thinkphp/base.php';
});
//use($http)
$http->on('request', function ($request, $response)
use($http) {
// if (!empty($_SERVER)) {
// unset($_SERVER);
// }
// $_SERVER= [];
if(isset($request->server)){
foreach ($request->server as $key => $value) {
$_SERVER[strtoupper($key)] = $value;
}
}
if(isset($request->header)){
foreach ($request->header as $key => $value) {
$_SERVER[strtoupper($key)] = $value;
}
}
// if (!empty($_GET)) {
// unset($_GET);
// }
// $_GET=[];
if(isset($request->get)){
foreach ($request->get as $key => $value) {
$_GET[strtoupper($key)] = $value;
}
}
// if (!empty($_POST)) {
// unset($_POST);
// }
// $_POST =[];
if(isset($request->post)){
foreach ($request->post as $key => $value) {
$_POST[strtoupper($key)] = $value;
}
}
ob_start();
try {
think\Container::get('app')->run()->send();
} catch (\Exception $e) {
}
$res=ob_get_contents();
ob_end_clean();
$response->end($res);
// $http->close();
});
$http->start();
function path() { }
// , $this->path
function pathinfo() { }
// , $this->pathinfo
pathinfo , function pathinfo() { }
if (isset($_SERVER['PATH_INFO']) && $_SERVER['PATH_INFO'] != '/')
{
return ltrim($_SERVER['PATH_INFO'], '/');
}