为什么ob_get_contents()获取不到数据呢
来源:7-5 让Swoole完美支持TP5(下)
慕少5137873
2019-11-03
<?php
/**
*User
*/
$http_server = new Swoole\Http\Server("0.0.0.0", 8811);
$http_server->set(
[
'enable_static_handler' => true,
'document_root' => '/data/wwwroot/www/tp5/public/static',
'worker_num' => 5,
]
);
$http_server->on('WorkerStart', function (swoole_server $server, $server_id) {
require __DIR__ . '/../thinkphp/base.php';
});
$http_server->on('request', function ($request, $response) use ($http_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;
}
}
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')->run()->send();
} catch (\Exception $e) {
//
print_r("<pre>");
var_dump($e);
print_r("<pre/>");
}
//echo request()->action().PHP_EOL;
$res = ob_get_contents();
var_dump($res);
if (ob_get_length() > 0) {
ob_end_clean();
}
$response->end($res);
//$http_server->close();
});
$http_server->start();
打印的是false,但是index方法里面的东西输出到xshell页面了
写回答
1回答
-
singwa
2019-11-04
您好。TP 和 PHP 分别是哪个版本?
032020-09-14
相似问题