ob_end_clean报错
来源:7-6 让Swoole完美支持TP5优化篇(上)
shaoslu
2018-07-20
老师你好,我已经修改了request.php的代码,但是action还是不起作用,而且还报了ob_end_clean的错误
swoole版本: 2.1.2-alpha
错误信息:
ERROR zm_deactivate_swoole (ERROR 503): Fatal error: Uncaught think\exception\ErrorException: ob_end_clean(): failed to delete buffer. No buffer to delete in /opt/htdocs/swoole/thinkphp5/server/http_server.php:73
Stack trace:
#0 [internal function]: think\Error::appError(8, 'ob_end_clean():...', '/opt/htdocs/swo...', 73, Array)
#1 /opt/htdocs/swoole/thinkphp5/server/http_server.php(73): ob_end_clean()
#2 {main}
thrown in /opt/htdocs/swoole/thinkphp5/server/http_server.php on line 73.
写回答
1回答
-
shaoslu
提问者
2018-07-20
<?php $host = '0.0.0.0'; $port = 8812; $server = new swoole_http_server($host, $port); $server->set([ 'enable_static_handler' => true, 'document_root' => '/opt/htdocs/swoole/thinkphp5/public/static', 'worker_num' => 5, ]); //此事件在Worker进程/Task进程启动时发生,这里创建的对象可以在进程生命周期内使用 $server->on('WorkerStart', function (swoole_server $serv, $worker_id){ //定义应用目录 //define('APP_PATH', __DIR__ . '/../application/'); //加载框架里面的文件 require __DIR__ . '/../thinkphp/base.php'; }); /** * 获取请求 * request: 请求信息 * response: 返回信息 */ $server->on('request', function($request, $response) use ($server){ /** * 解决上一次输入的变量还存在的问题 * 方案一:if(!empty($_GET)) {unset($_GET);} * 方案二:$http-close();把之前的进程kill,swoole会重新启一个进程,重启会释放内存,把上一次的资源包括变量等全部清空(如果用这个方法那就和php-fpm一样了,所以不推荐使用) * 方案三:$_SERVER = [] * 方案四:改thinkphp 代码 * /opt/htdocs/swoole/thinkphp5/thinkphp/library/think/Request.php * 屏蔽 if (is_null($this->path)) { * 屏蔽 if (is_null($this->pathinfo)) { */ if($request->server){ foreach($request->server as $k=>$v){ $_SERVER[strtoupper($k)] = $v; } } if($request->header){ foreach($request->header as $k=>$v){ $_SERVER[strtoupper($k)] = $v; } } if($request->get){ foreach($request->get as $k=>$v){ $_GET[$k] = $v; } } if($request->post){ foreach($request->post as $k=>$v){ $_POST[$k] = $v; } } ob_start(); try{ think\Container::get('app', [defined('APP_PATH') ? APP_PATH : '']) ->run() ->send(); }catch (Exception $e) { } $res = ob_get_contents(); ob_end_clean(); $response->end($res); }); $server->start();
022019-04-05
相似问题