From e35a0a88ac60eee755c4a22712cce4c3a28ca33c Mon Sep 17 00:00:00 2001 From: thinkphp Date: Thu, 7 Jul 2016 11:55:57 +0800 Subject: [PATCH] =?UTF-8?q?=E7=A7=BB=E9=99=A4sae=E9=A9=B1=E5=8A=A8=20?= =?UTF-8?q?=E6=94=B9=E4=B8=BA=E6=89=A9=E5=B1=95=E5=8C=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- convention.php | 2 +- library/think/cache/driver/Sae.php | 122 -------------------- library/think/log/driver/Sae.php | 71 ------------ library/think/template/driver/Sae.php | 109 ----------------- tests/thinkphp/library/think/loaderTest.php | 1 - 5 files changed, 1 insertion(+), 304 deletions(-) delete mode 100644 library/think/cache/driver/Sae.php delete mode 100644 library/think/log/driver/Sae.php delete mode 100644 library/think/template/driver/Sae.php diff --git a/convention.php b/convention.php index 6db8300d..87fe69eb 100644 --- a/convention.php +++ b/convention.php @@ -144,7 +144,7 @@ return [ // +---------------------------------------------------------------------- 'log' => [ - // 日志记录方式,内置 file sae socket 支持扩展 + // 日志记录方式,内置 file socket 支持扩展 'type' => 'File', // 日志保存目录 'path' => LOG_PATH, diff --git a/library/think/cache/driver/Sae.php b/library/think/cache/driver/Sae.php deleted file mode 100644 index fbc20979..00000000 --- a/library/think/cache/driver/Sae.php +++ /dev/null @@ -1,122 +0,0 @@ - -// +---------------------------------------------------------------------- - -namespace think\cache\driver; - -use think\Cache; -use think\Exception; - -/** - * SAE Memcache缓存驱动 - * @author liu21st - */ -class Sae -{ - protected $handler = null; - protected $options = [ - 'host' => '127.0.0.1', - 'port' => 11211, - 'expire' => 0, - 'timeout' => false, - 'persistent' => false, - 'prefix' => '', - ]; - - /** - * 架构函数 - * @param array $options 缓存参数 - * @access public - */ - public function __construct($options = []) - { - if (!function_exists('memcache_init')) { - throw new \BadFunctionCallException('must run at sae'); - } - $this->handler = memcache_init(); - if (!$this->handler) { - throw new Exception('memcache init error'); - } - if (!empty($options)) { - $this->options = array_merge($this->options, $options); - } - } - - /** - * 读取缓存 - * @access public - * @param string $name 缓存变量名 - * @return mixed - */ - public function get($name) - { - return $this->handler->get($_SERVER['HTTP_APPVERSION'] . '/' . $this->options['prefix'] . $name); - } - - /** - * 写入缓存 - * @access public - * @param string $name 缓存变量名 - * @param mixed $value 存储数据 - * @param integer $expire 有效时间(秒) - * @return bool - */ - public function set($name, $value, $expire = null) - { - if (is_null($expire)) { - $expire = $this->options['expire']; - } - $name = $this->options['prefix'] . $name; - if ($this->handler->set($_SERVER['HTTP_APPVERSION'] . '/' . $name, $value, 0, $expire)) { - return true; - } - return false; - } - - /** - * 删除缓存 - * @param string $name 缓存变量名 - * @param bool|false $ttl - * @return bool - */ - public function rm($name, $ttl = false) - { - $name = $_SERVER['HTTP_APPVERSION'] . '/' . $this->options['prefix'] . $name; - return false === $ttl ? - $this->handler->delete($name) : - $this->handler->delete($name, $ttl); - } - - /** - * 清除缓存 - * @access public - * @return bool - */ - public function clear() - { - return $this->handler->flush(); - } - - /** - * 获得SaeKv对象 - */ - private function getKv() - { - static $kv; - if (!$kv) { - $kv = new \SaeKV(); - if (!$kv->init()) { - throw new Exception('KVDB init error'); - } - } - return $kv; - } - -} diff --git a/library/think/log/driver/Sae.php b/library/think/log/driver/Sae.php deleted file mode 100644 index c593c09e..00000000 --- a/library/think/log/driver/Sae.php +++ /dev/null @@ -1,71 +0,0 @@ - ' c ', - ]; - - // 实例化并传入参数 - public function __construct(array $config = []) - { - $this->config = array_merge($this->config, $config); - } - - /** - * 日志写入接口 - * @access public - * @param array $log 日志信息 - * @return bool - */ - public function save(array $log = []) - { - static $is_debug = null; - $now = date($this->config['log_time_format']); - // 获取基本信息 - if (isset($_SERVER['HTTP_HOST'])) { - $current_uri = $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']; - } else { - $current_uri = "cmd:" . implode(' ', $_SERVER['argv']); - } - $runtime = number_format(microtime(true), 8, '.', '') - THINK_START_TIME; - $reqs = number_format(1 / $runtime, 2); - $time_str = " [运行时间:{$runtime}s] [吞吐率:{$reqs}req/s]"; - $memory_use = number_format((memory_get_usage() - THINK_START_MEM) / 1024, 2); - $memory_str = " [内存消耗:{$memory_use}kb]"; - $file_load = " [文件加载:" . count(get_included_files()) . "]"; - - $info = '[ log ] ' . $current_uri . $time_str . $memory_str . $file_load . "\r\n"; - foreach ($log as $type => $val) { - foreach ($val as $msg) { - if (!is_string($msg)) { - $msg = var_export($msg, true); - } - $info .= '[ ' . $type . ' ] ' . $msg . "\r\n"; - } - } - - $logstr = "[{$now}] {$_SERVER['SERVER_ADDR']} {$_SERVER['REMOTE_ADDR']} {$_SERVER['REQUEST_URI']}\r\n{$info}\r\n"; - if (is_null($is_debug)) { - $appSettings = []; - preg_replace_callback('@(\w+)\=([^;]*)@', function ($match) use (&$appSettings) { - $appSettings[$match['1']] = $match['2']; - }, $_SERVER['HTTP_APPCOOKIE']); - $is_debug = in_array($_SERVER['HTTP_APPVERSION'], explode(',', $appSettings['debug'])) ? true : false; - } - if ($is_debug) { - sae_set_display_errors(false); //记录日志不将日志打印出来 - } - sae_debug($logstr); - if ($is_debug) { - sae_set_display_errors(true); - } - return true; - } - -} diff --git a/library/think/template/driver/Sae.php b/library/think/template/driver/Sae.php deleted file mode 100644 index 9e5230a5..00000000 --- a/library/think/template/driver/Sae.php +++ /dev/null @@ -1,109 +0,0 @@ - -// +---------------------------------------------------------------------- - -namespace think\template\driver; - -use think\Exception; - -class Sae -{ - // mc 对象 - private $mc; - // 编译缓存内容 - private $contents = []; - - /** - * 架构函数 - * @access public - */ - public function __construct() - { - if (!function_exists('memcache_init')) { - throw new Exception('请在SAE平台上运行代码。'); - } - $this->mc = @memcache_init(); - if (!$this->mc) { - throw new Exception('您未开通Memcache服务,请在SAE管理平台初始化Memcache服务'); - } - } - - /** - * 写入编译缓存 - * @param string $cacheFile 缓存的文件名 - * @param string $content 缓存的内容 - * @return void|array - */ - public function write($cacheFile, $content) - { - // 添加写入时间 - $content = $_SERVER['REQUEST_TIME'] . $content; - if (!$this->mc->set($cacheFile, $content, MEMCACHE_COMPRESSED, 0)) { - throw new Exception('sae mc write error:' . $cacheFile); - } else { - $this->contents[$cacheFile] = $content; - return true; - } - } - - /** - * 读取编译编译 - * @param string $cacheFile 缓存的文件名 - * @param array $vars 变量数组 - * @return void - */ - public function read($cacheFile, $vars = []) - { - if (!empty($vars) && is_array($vars)) { - extract($vars, EXTR_OVERWRITE); - } - eval('?>' . $this->get($cacheFile, 'content')); - } - - /** - * 检查编译缓存是否有效 - * @param string $cacheFile 缓存的文件名 - * @param int $cacheTime 缓存时间 - * @return boolean - */ - public function check($cacheFile, $cacheTime) - { - $mtime = $this->get($cacheFile, 'mtime'); - if (0 != $cacheTime && $_SERVER['REQUEST_TIME'] > $mtime + $cacheTime) { - // 缓存是否在有效期 - return false; - } - return true; - } - - /** - * 读取文件信息 - * @access private - * @param string $filename 文件名 - * @param string $name 信息名 mtime或者content - * @return boolean - */ - private function get($filename, $name) - { - if (!isset($this->contents[$filename])) { - $this->contents[$filename] = $this->mc->get($filename); - } - $content = $this->contents[$filename]; - - if (false === $content) { - return false; - } - $info = array( - 'mtime' => substr($content, 0, 10), - 'content' => substr($content, 10), - ); - return $info[$name]; - } -} diff --git a/tests/thinkphp/library/think/loaderTest.php b/tests/thinkphp/library/think/loaderTest.php index 4c9acd77..a33c30c9 100644 --- a/tests/thinkphp/library/think/loaderTest.php +++ b/tests/thinkphp/library/think/loaderTest.php @@ -53,7 +53,6 @@ class loaderTest extends \PHPUnit_Framework_TestCase public function testImport() { - $this->assertEquals(true, Loader::import('think.log.driver.Sae')); $this->assertEquals(false, Loader::import('think.log.driver.MyTest')); }