【问题标题】:Zend_Cache_Frontend_Page does not recognize output without echoZend_Cache_Frontend_Page 无法识别没有回显的输出
【发布时间】:2012-01-10 22:31:26
【问题描述】:

我正在尝试使用 Zend_Cache,所以我在我的操作中添加了以下代码(我猜稍后将移至引导程序):

$frontendOptions = array(
    'lifetime' => 7200,
    'debug_header' => true, // für das Debuggen
    'default_options' => array(
        'cache' => true,
        'cache_with_get_variables' => true,
        'cache_with_session_variables' => true,
        'cache_with_cookie_variables' => true,
        'cache_with_post_variables' => true,
    )
);

$backendOptions = array(
    'cache_dir' => '/tmp/'
);

$cache = Zend_Cache::factory('Page', 'File',
    $frontendOptions, $backendOptions
);
echo "hej";
var_dump($cache->start('someid'));

Zend 现在生成一个包含hejbool(false) 的缓存文件,但除此之外它不会缓存我的页面。根据一本关于​​ zend 框架的德国书籍,当 没有可用的缓存 时,false 是正确的。只有在找到缓存时才返回 true。

当我直接在Zend_Cache_Frontend_Page.php 中调试时,它会下降到 start() 方法的底部,这意味着没有任何问题(给定 id)并且没有找到缓存,所以必须生成一个。已完成(我可以在 /tmp/ 中看到它),但没有所需的内容。

那为什么不缓存Zend_View的输出,而只缓存echo的直接输出呢?

我没有调用任何显式函数来呈现视图,但这似乎不再需要(我的视图总是根据控制器和操作自动呈现)。我尝试了标准 XHTML 模板 (index.phtml) 和 RSS 模板 (index.rss.phtml)。

有什么想法吗?您还需要其他代码片段吗?

【问题讨论】:

  • 您是否在 Bootstrap 中添加了 Zend_Controller_Front::getInstance()->setParam('disableOutputBuffering', true) 或在应用程序的配置文件中添加了 resources.frontController.params.disableOutputBuffering = true
  • 觉得这很简单 ;) 将其添加为答案,这样我就可以将其标记为已解决并给你一些积分。

标签: zend-framework


【解决方案1】:

使用Zend_Cache_Frontend_Page 时,您必须启用disableOutputBuffering 选项。原因是Zend_Cache_Frontend_Page 使用带有回调的ob_start,它必须是对ob_start 的第一次调用,否则会导致您遇到的奇怪行为。

要启用它,您可以在 Bootstrap 中设置它

Zend_Controller_Front::getInstance()->setParam('disableOutputBuffering', true);

或者在你的frontController-setup之后使用配置文件(这里是INI风格的配置):

resources.frontController.params.disableOutputBuffering = true

【讨论】:

    猜你喜欢
    • 2020-11-06
    • 2021-10-20
    • 2013-06-12
    • 2017-07-31
    • 2012-03-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-01-24
    相关资源
    最近更新 更多