【问题标题】:ZF1 + phpbb 3.1.5 - problems with $cache->getZF1 + phpbb 3.1.5 - $cache->get 的问题
【发布时间】:2015-07-29 15:59:38
【问题描述】:

运行 ZF1 并链接到 phpbb 论坛的站点。
将phpbb从3.0.12更新到3.1.5(3.0.12没有这个问题)

当我直接访问论坛时,它可以正常工作。

但是通过框架访问它时
(例如访问data['user_unread_privmsg']等用户功能)
我收到以下错误:

Call to undefined method Zend_Cache_Core::get() in /forum/phpbb/db/driver/mysqli.php on line 119

我已经通过使用 xe-debug 进行了跟踪,它在以下函数处停止:

/**
    * {@inheritDoc}
    */
    function sql_server_info($raw = false, $use_cache = true)
    {
        global $cache;

        if (!$use_cache || empty($cache) || ($this->sql_server_version = $cache->get('mysqli_version'))  === false)
        {
            $result = @mysqli_query($this->db_connect_id, 'SELECT VERSION() AS version');
            if ($result !== null)
            {
                $row = @mysqli_fetch_assoc($result);

                $this->sql_server_version = $row['version'];

                if (!empty($cache) && $use_cache)
                {
                    $cache->put('mysqli_version', $this->sql_server_version);
                }
            }
            @mysqli_free_result($result);
        }

        return ($raw) ? $this->sql_server_version : 'MySQL(i) ' . $this->sql_server_version;
    }

导致错误的确切行如下
if (!$use_cache || empty($cache) || ($this->sql_server_version = $cache->get('mysqli_version')) === false)

我的 ZF 缓存设置(适用于其他缓存项)看起来像这样

$cachedir = APPLICATION_PATH . '/public/tmp/cache';

    if (!is_dir($cachedir)) {
        mkdir($cachedir, 0755, true);       // make directory if it doesn't exist
    }

    $frontendOptions = array(
        'lifetime' => 600,
        'automatic_serialization' => true
    );

    $backendOptions = array(
        'cache_dir' => $cachedir
    ); 

    // getting a Zend_Cache_Core object
    $cache = Zend_Cache::factory('Core', 'File', $frontendOptions, $backendOptions);

    Zend_Registry::set("cache", $cache);
    Zend_Db_Table_Abstract::setDefaultMetadataCache($cache);

    $cache = Zend_Cache::factory('Core', 'APC', $frontendOptions);
    Zend_Registry::set("apc_cache", $cache);

任何想法如何解决这个问题?

(我已经删除了旧缓存,将 tmp/cache 权限设置为 777 等)

【问题讨论】:

    标签: caching zend-framework mysqli phpbb


    【解决方案1】:

    phpBB 在全局范围内使用 $cache 变量(使用global $cache 将其导入函数范围)。它应该是 phpBB 的缓存类的实例,而不是 Zend_Cache_Core 类。

    有效地,通过分配这个:

    $cache = Zend_Cache::factory('Core', 'File', $frontendOptions, $backendOptions);
    

    你覆盖这里设置的全局变量:https://github.com/phpbb/phpbb/blob/3.1.x/phpBB/includes/compatibility_globals.php,一切都会爆炸。

    phpBB3 不擅长与另一个脚本一起包含并共享相同的范围和内存。最近它变得更好了(如您所见,链接的文件称为兼容性),但您仍然必须小心并谨慎编码。

    【讨论】:

    • 谢谢,很高兴知道 - 将我的 ZF 缓存设置命名更改为 $appCache,从而解决了问题!
    猜你喜欢
    • 2010-09-17
    • 2021-05-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-10-13
    • 1970-01-01
    • 2018-09-15
    • 1970-01-01
    相关资源
    最近更新 更多