服务器跑的Windows Server 2012R2,PHP v5.3.28。并不自带操作码缓存,因此使用wincache加速PHP执行。不过winCache自带User-data-cache缓存,这样导致Discuz默认选取其当作数据缓存。我这个实际情况里面出现了wincache 导致forum.php
异常加载时间长。分析问题出在数据缓存失效了。可能是wincache的bug。后来发现鸟哥的yac无锁缓存单机情况下可能是比较理想的,因此使用yac做数据缓存同时配合wincache的操作码缓存。
用的是discuz X3.3,memory缓存中有yac的文件,但是默认不支持,折腾一番得到下面的结果:
(1)搜索discuz_memory.php
,在构造函数中增加
$this->extension['yac'] = extension_loaded('Yac');
完整代码如下:
public function __construct() {
$this->extension['redis'] = extension_loaded('redis');
$this->extension['memcache'] = extension_loaded('memcache');
$this->extension['apc'] = function_exists('apc_cache_info') && @apc_cache_info();
$this->extension['xcache'] = function_exists('xcache_get');
$this->extension['eaccelerator'] = function_exists('eaccelerator_get');
$this->extension['wincache'] = function_exists('wincache_ucache_meminfo') && wincache_ucache_meminfo();
//在此添加yac的支持
$this->extension['yac'] = extension_loaded('Yac');
}
(2)同时在其init
函数搜索foreach(array('apc', 'eaccelerator', 'xcache', 'wincache') as $cache)
,增加一项yac
。
完整代码如下:
public function init($config) {
$this->config = $config;
$this->prefix = empty($config['prefix']) ? substr(md5($_SERVER['HTTP_HOST']), 0, 6).'_' : $config['prefix'];
if($this->extension['redis'] && !empty($config['redis']['server'])) {
$this->memory = new memory_driver_redis();
$this->memory->init($this->config['redis']);
if(!$this->memory->enable) {
$this->memory = null;
}
}
if($this->extension['memcache'] && !empty($config['memcache']['server'])) {
$this->memory = new memory_driver_memcache();
$this->memory->init($this->config['memcache']);
if(!$this->memory->enable) {
$this->memory = null;
}
}
//接上面所说我不用wincache的数据缓存了,因此删去了wincache
foreach(array('apc', 'eaccelerator', 'xcache', 'yac') as $cache) {
if(!is_object($this->memory) && $this->extension[$cache] && $this->config[$cache]) {
$class_name = 'memory_driver_'.$cache;
$this->memory = new $class_name();
$this->memory->init(null);
}
}
if(is_object($this->memory)) {
$this->enable = true;
$this->type = str_replace('memory_driver_', '', get_class($this->memory));
}
}
请注意使用之前正确添加了扩展。