ZF1 + phpbb 3.1.5 - $cache->get 问题
ZF1 + phpbb 3.1.5 - problems with $cache->get
链接到 phpbb 论坛的站点 运行 ZF1。
将 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 等)
phpBB 在全局范围内使用 $cache 变量(使用 global $cache
将其导入函数范围)。它应该是 phpBB 的缓存实例 class,而不是 Zend_Cache_Core
class.
有效地,通过分配这个:
$cache = Zend_Cache::factory('Core', 'File', $frontendOptions, $backendOptions);
你覆盖了这里设置的全局变量:https://github.com/phpbb/phpbb/blob/3.1.x/phpBB/includes/compatibility_globals.php 一切都爆炸了。
phpBB3 不擅长与另一个脚本一起包含并共享相同的范围和内存。它最近好多了(如您所见,链接的文件名为 compatability),但您仍然必须小心并谨慎编码。
链接到 phpbb 论坛的站点 运行 ZF1。
将 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 等)
phpBB 在全局范围内使用 $cache 变量(使用 global $cache
将其导入函数范围)。它应该是 phpBB 的缓存实例 class,而不是 Zend_Cache_Core
class.
有效地,通过分配这个:
$cache = Zend_Cache::factory('Core', 'File', $frontendOptions, $backendOptions);
你覆盖了这里设置的全局变量:https://github.com/phpbb/phpbb/blob/3.1.x/phpBB/includes/compatibility_globals.php 一切都爆炸了。
phpBB3 不擅长与另一个脚本一起包含并共享相同的范围和内存。它最近好多了(如您所见,链接的文件名为 compatability),但您仍然必须小心并谨慎编码。