完全安装老师来的 但我不管使用PATHINFO还是普通模式 都只能访问index
来源:7-5 让Swoole完美支持TP5(下)

hallo_monde
2018-04-24
<?php $http = new swoole_http_server("0.0.0.0", 8811); $http->set([ 'enable_static_handler' => true, 'document_root' => "/root/demoswoole/demo/thinkphp5.1/public/static", 'worker_num' => 5 ]); $http->on('WorkerStart', function (swoole_server $server, $worker_id) { define('APP_PATH', __DIR__ . '/../application/'); require __DIR__ . '/../thinkphp/base.php'; }); $http->on('request', function ($request, $response) use ($http) { // print_r($request->server); $_SERVER = []; if (isset($request->server)) { foreach ($request->server as $k => $v) { $_SERVER[strtoupper($k)] = $v; } } if (isset($request->header)) { foreach ($request->header as $k => $v) { $_SERVER[strtoupper($k)] = $v; } } $_GET = []; if (isset($request->get)) { foreach ($request->get as $k => $v) { $_GET[strtoupper($k)] = $v; } } $_POST = []; if (isset($request->post)) { foreach ($request->post as $k => $v) { $_POST[strtoupper($k)] = $v; } } ob_start(); try { think\Container::get('app', [APP_PATH])->run()->send; } catch (\Exception $exception) { } echo "<---action--->" . request()->action() . PHP_EOL; $res = ob_get_contents(); ob_end_clean(); $response->end($res); $http->close(); }); $http->start();
<?php namespace app\index\controller; class Index { public function index() { var_dump($_GET); echo 'hello world!'; } public function test() { echo time(); } public function hello($name = 'ThinkPHP5') { echo 'hello,' . $name; } }
写回答
3回答
-
Mccree丶果
2020-05-10
$_GET = [];
if (isset($request->get)) {
foreach ($request->get as $k => $v) {
$_GET[strtoupper($k)] = $v;//这里不能加转大写的方法
}
}
$_POST = [];
if (isset($request->post)) {
foreach ($request->post as $k => $v) {
$_POST[strtoupper($k)] = $v;
}
}
00 -
阿憨阿憨
2018-09-27
//注意看这里的uf $k== 's' if (isset($request->get)) { foreach ($request->get as $k => $v) { if($k == 's'){ $_GET[$k] = $v; }else{ $_GET[strtoupper($k)] = $v; } } }
原因, 查看request.php中的pathinfo()方法.
在虚拟机中,Linux系统的基佬们, 主要大小写问题.
00 -
singwa
2018-04-24
您好。 请继续看7-6节。 有优化。。希望能帮到你。
00
相似问题