public static function init($pcacher = null, $expire = 0) { return function ($info, $buffered = false) use($pcacher, $expire) { if (!$pcacher) { $pcacher = \Leb_Dao_Memcache::getInstance('applog'); } if (!$pcacher) { throw new \LogicException('Invalid cacher object.'); } // 8 = 4 + 2 + 2 // t + p + c // 64 = 32 + 10 + 15 + 7 // t + mt + p + c $bptime = explode(' ', microtime(false)); $pid = function_exists('posix_getpid') ? posix_getpid() : getmypid(); // $uid = (time() << 16 | ($pid % 0xFFFF)) << 16 | ((++ \Leb_Analog::$counter) % 0xFFFF); $uid = $bptime[1] << 10 | intval($bptime[0] * 1000); $uid = $uid << 15 | $pid % 0xfffe; $uid = $uid << 7 | ++\Leb_Analog::$counter % 0xfe; // $uuid = sprintf('%u', $uid); // var_dump($bptime[1], intval($bptime[0] * 1000), $pid, \Leb_Analog::$counter, $uid, $uuid); // exit; $bret = true; $bret = $pcacher->set($uid, json_encode($info), array('expire' => $expire)); if ($bret) { return $uid; } return $bret; }; }
/** * 获取表结构 */ public function getCacheAction() { $key = daddslashes($this->getVar('key')); //键名是:数据库名_表名 if (empty($key)) { return false; } $memcache = Leb_Dao_Memcache::getInstance(); $result = $memcache->get($key); var_dump($result); }
/** * 获取缓存对象 * * @return <type> */ public function getCacher() { if (!is_object($this->_cacher)) { $this->_cacher = Leb_Dao_Memcache::getInstance(); } return $this->_cacher; }
/** * 通过memcache来生成一个auto_increment序列, * * 序列类似MySQL的auto_increment。 * @return integer $nextval | false */ private function _getNextValueByMemcache() { $serial_key = $this->_shardAutoSerialKey; $cacher = Leb_Dao_Memcache::getInstance(); $auto_inc_sig = $cacher->inc($serial_key); if ($auto_inc_sig == false) { $cacher->set($serial_key, 1); $auto_inc_sig = $cacher->inc($serial_key); } return $auto_inc_sig; }
/** * 注册结束脚本回调函数 * @param 无 * @return void */ public static function shutdown() { !defined('__FRM_ACTION_END__') && define('__FRM_ACTION_END__', microtime(true)); $e = error_get_last(); if (defined('__FRM_ACTION_END__ ') && defined('__FRM_ACTION_BEGIN__')) { Slae::app()->log->info('Response:' . (__FRM_ACTION_END__ - __FRM_ACTION_BEGIN__), 'system'); } if (defined('__FRM_ACTION_BEGIN__') && defined('__FRM_BEGIN__')) { Slae::app()->log->info('Framework:' . (__FRM_ACTION_BEGIN__ - __FRM_BEGIN__), 'system'); } //路由分发日志信息 $route = new Leb_Log_Router(); $route->renderLog(); //无错误信息立即输出缓冲内容 if (empty($e)) { @flush(); @ob_flush(); @ob_end_flush(); if (function_exists('fastcgi_finish_request')) { fastcgi_finish_request(); } } Leb_Dao_Memcache::getInstance()->debugRtStats(); if (XHPROF_ANALYSIS && _DEBUG_ && function_exists('xhprof_disable')) { if ($data = xhprof_disable()) { Slae::app()->log->profile($data, 'system'); } //format //[ct] => 2 # number of calls to bar() from foo() //[wt] => 37 # time in bar() when called from foo() //[cpu]=> 0 # cpu time in bar() when called from foo() //[mu] => 2208 # change in PHP memory usage in bar() when called from foo() //[pmu]=> 0 # change in PHP peak memory usage in bar() when called from foo() } //捕捉错误信息 if (!empty($e)) { $code = $e['type']; $file = $e['file']; $line = $e['line']; $message = $e['message']; $er = Slae::app()->errorInfo($code, $message, $file, $line); if ($file && false !== strpos($file, dirname(__FILE__) . _DS_ . 'view' . _DS_ . 'Smarty')) { E_ERROR == $code && Slae::app()->showError($code, $message, $file, $line, $er, null); } elseif ($code & (E_ERROR | E_CORE_ERROR | E_COMPILE_ERROR | E_USER_ERROR | E_PARSE | E_RECOVERABLE_ERROR)) { Slae::app()->showError($code, $message, $file, $line, $er, null); } } //根据配置把日志刷入日志系统 }
/** * Handler getter/setter. If no handler is provided, it will set it to * sys_get_temp_dir() . '/analog.txt' as a default. Usage: * * Leb_Analog::handler ('my_log.txt'); * * Using a closure: * * Leb_Analog::handler (function ($msg) { * return error_log ($msg); * }); */ public static function handler($handler = false) { if ($handler) { self::$handler = $handler; } elseif (!self::$handler) { if (empty(self::$config)) { if (file_exists(dirname(__FILE__) . '/../config/log.php')) { self::$config = (include dirname(__FILE__) . '/../config/log.php'); } } if (empty(self::$config) || !isset(self::$config['type'])) { require_once 'Analog/File.php'; self::$handler = realpath(sys_get_temp_dir()) . DIRECTORY_SEPARATOR . 'analog.txt'; } else { if (isset(self::$config['app'])) { self::$app = self::$config['app']; } $expire = ''; if (isset(self::$config['expire'])) { $expire = intval(self::$config['expire']); } switch (self::$config['type']) { case 'memcache': require_once dirname(__FILE__) . '/Analog/couchbase.php'; $cacher = \Leb_Dao_Memcache::getInstance('applog'); if (empty($expire)) { self::$handler = \Analog\Couchbase::init($cacher); } else { self::$handler = \Analog\Couchbase::init($cacher, $expire); } break; case 'firephp': require_once dirname(__FILE__) . '/Analog/FirePHP.php'; self::$handler = \Analog\FirePHP::init(); break; default: require_once 'Analog/File.php'; self::$handler = realpath(sys_get_temp_dir()) . DIRECTORY_SEPARATOR . 'analog.txt'; } if (isset(self::$config['verbose'])) { switch (self::$config['verbose']) { case 'error': break; case 'info': self::$verbose = self::INFO; break; case 'debug': self::$verbose = self::DEBUG; break; } } } } return self::$handler; }