Smarty中的ob_start问题

简介:
近日升级php 4.3.10 到 4.4.6,遭遇到一个奇怪的问题。描述如下:
Linux Redhat AS4, Apache 1.3.37, PHP 4.4.6, Smarty 2.6.3 环境中,只要在调用 Smarty 的 display() 函数之前有任何诸如
echo/print/print_r 等输出,那么整个输出结果就变成空白页面。一开始以为是版本升级导致的问题,遂换成旧版本,问题依旧。也怀疑到是否因为 SQUID 缓存引起的,于是直接走 Apache 端口,还是那样。把 PHP 的 error_reporting 改成 E_ALL,重启,没看到任何报错,但是问题依旧如此...这时已经有点烦躁了。 以前也从来没碰到过如此BT之问题,百思不得其解,干脆重启机器吧,可还是那样...
把保存cache的目录权限设置成777,把cache清除,禁用cache...能想得到的都做了,可是,结果还是那样...
没办法,那只好debug调试程序了吧,于是就跟踪 Smarty 的源代码中的 display() 函数,发现调用了 ob 系列函数,于是怀疑和它们有关>系,于是关闭 ob 功能,问题消失。
究其原因,原来是在 Smarty 中调用了 ob_start() 函数,并且附带了参数 'ob_gzhandler',代码段如下:
@ob_start('ob_gzhandler');
$this->fetch($resource_name, $cache_id, $compile_id, true);
$content = @ob_get_contents();
if($content)
{
  @ob_end_clean();
  @ob_start('ob_gzhandler');
  echo $content;
  @ob_end_flush();
}
在这里,指定输出缓存(output_handler)要调用了 ob_gzhandler 函数。然而,在 php.ini 中的 output_handler
选项却没有打开,也就是无法支持 output_handler 了。打开 php.ini 文件,修改如下内容:
output_handler = ob_gzhandler;
指定 output_handler 的默认处理函数为 ob_gzhandler。重启 Apache,一切 OK。


本文转自叶金荣51CTO博客,原文链接:http://blog.51cto.com/imysql/308086,如需转载请自行联系原作者
相关文章
|
5月前
|
JavaScript
引入echarts时报错 “TypeError: Cannot read properties of undefined (reading ‘init‘)“的解决方案
引入echarts时报错 “TypeError: Cannot read properties of undefined (reading ‘init‘)“的解决方案
188 0
引入echarts时报错 “TypeError: Cannot read properties of undefined (reading ‘init‘)“的解决方案
|
10月前
|
PHP
PHP当中echo、print、 print_r、var_dump、var_export的异同
PHP当中echo、print、 print_r、var_dump、var_export的异同
|
10月前
|
PHP
thinkphp报错Call to undefined method app\index\controller\Index::fetch()
thinkphp报错Call to undefined method app\index\controller\Index::fetch()
98 0
|
应用服务中间件 nginx
[error] OpenEvent(“Global\ngx_reload_11812“) failed (2: The system cannot find the file specified
[error] OpenEvent(“Global\ngx_reload_11812“) failed (2: The system cannot find the file specified
|
缓存
【已解决】npm start 报错 Could not freeze ...: cannot read properties of undefined (reading ‘hash‘)
npm start 报错 Could not freeze ...: cannot read properties of undefined (reading ‘hash‘)
413 0
|
PHP
php中echo,print,print_r,var_dump 的区别
php中echo,print,print_r,var_dump 的区别
42 0
PHP:echo,print,print_r,var_dump区别
PHP:echo,print,print_r,var_dump区别
219 0
PHP:echo,print,print_r,var_dump区别
|
PHP
【PHP】call_user_func_array() 内置函数
【PHP】call_user_func_array() 内置函数
83 0
【PHP】call_user_func_array() 内置函数
|
缓存 PHP
PHP ob_start() 函数介绍
php ob_start 与 ob_end_flush() 是 php 的缓冲输出函数。 ob_start([string output_callback])- 打开输出缓冲区,所有的输出信息不在直接发送到浏览器,而是保存在输出缓冲区里面,可选得回调函数用于处理输出结果信息。
1249 0