83530391 2020-05-05
<?phpclass Memcacheds{ //声明静态成员变量 private static $m = null; private static $cache = null; public function __construct() { self::$m = new Memcached(); self::$m->addServer(‘127.0.0.1‘,‘11211‘); //写入缓存地址,port } //为当前类创建对象 private static function Men(){ self::$cache = new Memcacheds(); return self::$m; } /* * 加入缓存数据 * @param string $key 获取数据唯一key * @param String||Array $value 缓存数据 * @param $time memcache生存周期(秒) */ public static function setMen($key,$value,$time){ self::Men()->set($key,$value,$time); } /* * 获取缓存数据 * @param string $key * @return */ public static function getMen($key){ return self::Men()->get($key); } /* * 删除相应缓存数据 * @param string $key * @return */ public static function delMen($key){ self::Men()->delete($key); } /* * 删除全部缓存数据 */ public static function delAllMen(){ self::Men()->flush(); } /* * 删除全部缓存数据 */ public static function menStatus(){ return self::Men()->getStats(); } }?>
//引入类文件 require dirname(__FILE__).‘/memcached.class.php‘; function Get_memcached($str,$key,$time){ $key = md5($key); Memcacheds::setMen($key,$str,$time); //写入缓存 $get = Memcacheds::getMen($key); //读取缓存 return $get; } echo function Get_memcached(‘data‘,‘key‘,3600);
希望本文所述对大家的php程序设计有所帮助。
<?php. if (!empty($_POST)) {. $data1 = $_POST["data1"];$data2 = $_POST["data2"];$fuhao = $_POST["fuh