zoukankan      html  css  js  c++  java
  • PHP共享内存yac操作类

    http://www.laruence.com/2013/03/18/2846.html   鸟哥介绍

    https://www.cnblogs.com/willamwang/p/8918377.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();
        }
    
    }
  • 相关阅读:
    非专业码农 JAVA学习笔记 3 抽象、封装和类(1)
    非计算机专业的码农C#学习笔记 三、变量 表达式 字符串
    非专业码农 JAVA学习笔记 2 java语言基础
    非计算机专业的码农C#学习笔记 五、数组和集合
    PSP个人软件开发工具
    端口映射
    $.proxy()
    input type=button设置高度不管用
    移动端日期控件
    mac终端下svn常用命令
  • 原文地址:https://www.cnblogs.com/wt645631686/p/10643105.html
Copyright © 2011-2022 走看看