跟着视频做到7-5节中打印$_GET的内容的时候,只要一加上参数就显示一片空白
来源:7-5 让Swoole完美支持TP5(下)
慕斯8244746
2019-07-12
下面是代码
<?php
/**
* Created by PhpStorm.
* User: baidu
* Date: 18/2/28
* Time: 上午1:39
*/
$http = new swoole_http_server("0.0.0.0", 8811);
$http->set(
[
'enable_static_handler' => true,
'document_root' => "/usr/local/project/thinkphp/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) {
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;
}
}
if(isset($request->get)){
foreach ($request->get as $k =>$v){
$_GET[$k]=$v;
}
}
if(isset($request->post)){
foreach ($request->post as $k =>$v){
$_POST[$k]=$v;
}
}
ob_start();
try{
think\Container::get('app', [APP_PATH ])
->run()
->send();
}catch (\Exception $e)
{
}
$res=ob_get_contents();
ob_end_clean();
$response->end($res);
});
$http->start();
<?php
namespace app\index\controller;
class Index
{
public function index()
{
print_r($_GET);
echo 'singwa-hello';
}
public function hello($name = 'ThinkPHP5')
{
return 'hello,' . $name;
}
}
写回答
3回答
-
亲爱的同学您好。swoole版本多少.
022019-07-12 -
慕斯8244746
提问者
2019-07-12
问题解决了,谢谢老师了,真的是swoole版本的问题。我装的那个是最新版本所以出问题了。不过更新几个版本就用不了了,swoole这变化也太大了吧。
012019-07-12 -
singwa
2019-07-12
您是说添加类似这种参数吗?
012019-07-12
相似问题