From abdc492b9a7bc12836ca24a35363b02fbc84b6dc Mon Sep 17 00:00:00 2001 From: Discuz! Date: Thu, 9 Feb 2017 15:24:36 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=20=E6=96=87=E4=BB=B6?= =?UTF-8?q?=E7=BC=93=E5=AD=98=EF=BC=8C=E5=B9=B6=E5=AE=89=E8=A3=85=E5=90=8E?= =?UTF-8?q?=E9=BB=98=E8=AE=A4=E5=BC=80=E5=90=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- upload/config/config_global_default.php | 13 +-- .../class/memory/memory_driver_file.php | 102 ++++++++++++++++++ 2 files changed, 109 insertions(+), 6 deletions(-) create mode 100644 upload/source/class/memory/memory_driver_file.php diff --git a/upload/config/config_global_default.php b/upload/config/config_global_default.php index c10b824..51ea51e 100644 --- a/upload/config/config_global_default.php +++ b/upload/config/config_global_default.php @@ -111,12 +111,13 @@ $_config['memory']['memcache']['port'] = 11211; // memcache 服务器端口 $_config['memory']['memcache']['pconnect'] = 1; // memcache 是否长久连接 $_config['memory']['memcache']['timeout'] = 1; // memcache 服务器连接超时 -$_config['memory']['apc'] = 1; // 启动对 APC 的支持 -$_config['memory']['apcu'] = 1; // 启动对 APCu 的支持 -$_config['memory']['xcache'] = 1; // 启动对 xcache 的支持 -$_config['memory']['eaccelerator'] = 1; // 启动对 eaccelerator 的支持 -$_config['memory']['wincache'] = 1; // 启动对 wincache 的支持 -$_config['memory']['yac'] = 1; //启动对 YAC的支持 +$_config['memory']['apc'] = 0; // 启动对 APC 的支持 +$_config['memory']['apcu'] = 0; // 启动对 APCu 的支持 +$_config['memory']['xcache'] = 0; // 启动对 xcache 的支持 +$_config['memory']['eaccelerator'] = 0; // 启动对 eaccelerator 的支持 +$_config['memory']['wincache'] = 0; // 启动对 wincache 的支持 +$_config['memory']['yac'] = 0; //启动对 YAC 的支持 +$_config['memory']['file']['server'] = 'data/cache/filecache'; // 启动对 File 缓存的支持 // 服务器相关设置 $_config['server']['id'] = 1; // 服务器编号,多webserver的时候,用于标识当前服务器的ID diff --git a/upload/source/class/memory/memory_driver_file.php b/upload/source/class/memory/memory_driver_file.php new file mode 100644 index 0000000..04d710a --- /dev/null +++ b/upload/source/class/memory/memory_driver_file.php @@ -0,0 +1,102 @@ +path = $config['server'].'/'; + if($config['server']) { + $this->enable = is_dir(DISCUZ_ROOT.$this->path); + if(!$this->enable) { + dmkdir(DISCUZ_ROOT.$this->path); + $this->enable = is_dir(DISCUZ_ROOT.$this->path); + } + } else { + $this->enable = false; + } + } + + private function cachefile($key) { + return str_replace('_', '/', $key).'/'.$key; + } + + public function get($key) { + $data = false; + @include_once DISCUZ_ROOT.$this->path.$this->cachefile($key).'.php'; + if($data !== false) { + if($data['exp'] && $data['exp'] < TIMESTAMP) { + return false; + } + return $data['data']; + } + } + + public function set($key, $value, $ttl = 0) { + $file = DISCUZ_ROOT.$this->path.$this->cachefile($key).'.php'; + dmkdir(dirname($file)); + $data = array( + 'exp' => $ttl ? TIMESTAMP + $ttl : 0, + 'data' => $value, + ); + return file_put_contents($file, "path.$this->cachefile($key)); + } + + private function dir_clear($dir) { + if($directory = @dir($dir)) { + while($entry = $directory->read()) { + $filename = $dir.'/'.$entry; + if($entry != '.' && $entry != '..') { + if(is_file($filename)) { + @unlink($filename); + } else { + $this->dir_clear($filename); + @rmdir($filename); + } + } + } + $directory->close(); + } + } + + public function clear() { + return $this->dir_clear(DISCUZ_ROOT.$this->path); + } + + public function inc($key, $step = 1) { + $old = $this->get($key); + if (!$old) { + return false; + } + return $this->set($key, $old + $step); + } + + public function dec($key, $step = 1) { + $old = $this->get($key); + if (!$old) { + return false; + } + return $this->set($key, $old - $step); + } + +}