PHP共享內存yac操做類

http://www.laruence.com/2013/03/18/2846.html   鳥哥介紹php

https://www.cnblogs.com/willamwang/p/8918377.html  擴展安裝html

<?php /** * 進程間共享內存操做類 */
class Pshmop { protected static $_models = array(); private $_yac = null; private static $_keyPrefix = 'shm_'; private static $_ttlMaxTime = 7776000;  //86400*90 爲防止永久貯存及保存時間太久形成內存消耗嚴重致使數據被踢出

    /** * Returns the static model of the specified AR class. * @param string $className active record class name. * @return Order the static model class */
    public static function model($className = __CLASS__) { $model = null; if (isset(self::$_models[$className])) $model = self::$_models[$className]; else { $model = self::$_models[$className] = new $className(null); } return $model; } public function __construct() { if(extension_loaded("yac")){ $this->_yac = new Yac(self::$_keyPrefix); } } /** * add value * @param mixed $keys * @param mixed $value * @param int $ttl * @return mixed */
    public function add($key, $value, $ttl=-1){ if(empty($key)){ return null; } if(empty($this->_yac)){ return null; } if($ttl<0 || $ttl>self::$_ttlMaxTime){ $ttl = self::$_ttlMaxTime; } return $this->_yac->add($key, $value, $ttl); } /** * set value * @param mixed $keys * @param mixed $value * @param int $ttl * @return mixed */
    public function set($key, $value, $ttl=-1){ if(empty($key)){ return null; } if(empty($this->_yac)){ return null; } if($ttl<0 || $ttl>self::$_ttlMaxTime){ $ttl = self::$_ttlMaxTime; } return $this->_yac->set($key, $value, $ttl); } /** * get value * @param mixed $keys * @return mixed */
    public function get($key){ if(empty($key)){ return null; } if(empty($this->_yac)){ return null; } return $this->_yac->get($key); } /** * delete key * @param mixed $keys * @param int $delay * @return mixed */
    public function delete($key, $delay=0){ if(empty($key)){ return null; } if(empty($this->_yac)){ return null; } return $this->_yac->delete($key, $delay); } /** * flush shm * @param void * @return mixed */
    public function flush(){ if(empty($this->_yac)){ return null; } return $this->_yac->flush(); } /** * get shm info * @param void * @return mixed */
    public function info(){ if(empty($this->_yac)){ return null; } return $this->_yac->info(); } }
相關文章
相關標籤/搜索