phpcms 添加memcache支持
1,修改caches/configs/cache.php
<?php return array (
‘file1‘ => array (
‘type‘ => ‘file‘,
‘debug‘ => true,
‘pconnect‘ => 0,
‘autoconnect‘ => 0
),
‘memcache1‘ => array (
‘hostname‘ => ‘127.0.0.1‘,
‘port‘ => 11211,
‘timeout‘ => 0,
‘type‘ => ‘memcache‘,
‘debug‘ => true,
‘pconnect‘ => 0,
‘autoconnect‘ => 0
)
); ?>
2,修改phpcms/libs/functions/globl.func.php 文件的四个函数
function setcache($name, $data, $filepath=‘‘, $type=‘memcache‘, $config=‘memcache1‘, $timeout=0) {
pc_base::load_sys_class(‘cache_factory‘,‘‘,0);
if($config) {
$cacheconfig = pc_base::load_config(‘cache‘);
$cache = cache_factory::get_instance($cacheconfig)->get_cache($config);
} else {
$cache = cache_factory::get_instance()->get_cache($type);
}
return $cache->set($name, $data, $timeout, ‘‘, $filepath);
}
function getcache($name, $filepath=‘‘, $type=‘memcache‘, $config=‘memcache1‘) {
pc_base::load_sys_class(‘cache_factory‘,‘‘,0);
if($config) {
$cacheconfig = pc_base::load_config(‘cache‘);
$cache = cache_factory::get_instance($cacheconfig)->get_cache($config);
} else {
$cache = cache_factory::get_instance()->get_cache($type);
}
return $cache->get($name, ‘‘, ‘‘, $filepath);
}
function delcache($name, $filepath=‘‘, $type=‘memcache‘, $config=‘memcache1‘) {
pc_base::load_sys_class(‘cache_factory‘,‘‘,0);
if($config) {
$cacheconfig = pc_base::load_config(‘cache‘);
$cache = cache_factory::get_instance($cacheconfig)->get_cache($config);
} else {
$cache = cache_factory::get_instance()->get_cache($type);
}
return $cache->delete($name, ‘‘, ‘‘, $filepath);
}
function getcacheinfo($name, $filepath=‘‘, $type=‘memcache‘, $config=‘memcache1‘) {
pc_base::load_sys_class(‘cache_factory‘);
if($config) {
$cacheconfig = pc_base::load_config(‘cache‘);
$cache = cache_factory::get_instance($cacheconfig)->get_cache($config);
} else {
$cache = cache_factory::get_instance()->get_cache($type);
}
return $cache->cacheinfo($name, ‘‘, ‘‘, $filepath);
}
3,修改phpcms/libs/classes/cache_memcache.class.php
<?php
class cache_memcache { private $memcache = null; public function __construct() {
$this->memcache = new Memcache;
$this->memcache->connect(MEMCACHE_HOST, MEMCACHE_PORT)or die ("Could not connect");
} public function memcache() {
$this->__construct();
} public function get($name, $empty=‘‘, $empty=‘‘,$filepath) {
$value = $this->memcache->get($name.$filepath);
return $value;
} public function cacheinfo($name, $empty=‘‘, $empty=‘‘, $filepath){
$value = $this->memcache->get($name.$filepath);
return $value;
} public function set($name, $value, $ttl = 3600, $ext1=‘‘, $ext2=‘‘) {
return $this->memcache->set($name.$ext2, $value, false, $ttl);
} public function delete($name, $empty=‘‘, $empty=‘‘, $filepath) {
return $this->memcache->delete($name.$filepath);
} public function flush() {
return $this->memcache->flush();
}
}
?>
4,测试调用文件(保持到网站根目录查看)
<?php
header(‘Content-type: text/html; charset=utf8‘);
echo "<pre>";
$host=‘127.0.0.1‘;
$port=11211;
$mem=new Memcache();
$mem->connect($host,$port); $mem->set(‘var_key‘, ‘some variable‘, 0, 30);//设置 $var = $mem->get(‘var_key‘);//获取 echo $var; $mem->add(‘xxx‘,‘fffffffff‘,0,80);//添加
$mem->delete(‘xxx‘, 10);//删除
$var = $mem->get(‘xxx‘);
echo $var; $items=$mem->getExtendedStats (‘items‘);
$items=$items["$host:$port"][‘items‘];
foreach($items as $key=>$values){
$number=$key;;
$str=$mem->getExtendedStats ("cachedump",$number,0);
$line=$str["$host:$port"];
if( is_array($line) && count($line)>0){
foreach($line as $key=>$value){
echo $key.‘=>‘;
print_r($mem->get($key));
echo "\r\n"."<br>";
}
}
}
?>
ok!
phpcms 添加memcache支持的更多相关文章
- 把自己Github上的代码添加Cocoapods支持
转载请注明原链接:http://www.cnblogs.com/zhanggui/p/6003481.html 一.前言 这两天被cocoapods折磨的心力憔悴.看cocoapods官网的添加支持, ...
- Spring Boot 添加Shiro支持
前言: Shiro是一个权限.会话管理的开源Java安全框架:Spring Boot集成Shiro后可以方便的使用Session: 工程概述: (工程结构图) 一.建立Spring Boot工程 参照 ...
- 在IntelliJ IDEA中添加框架支持时找不到Hibernate的解决办法
问题描述 第一次在Add Frameworks support界面中添加hibernate支持的时候,异常中断,导致没有成功添加. 第二次进入Add Frameworks support窗口时,发现找 ...
- 别再为了iOS新系统设备而重新安装一个新版Xcode了.其实我们可以添加版本支持
众所周知,Xcode7.3的代码补全是有问题的 如导入自定义类之后,在代码中并不会补全相应的类名... 但Xcode7.2是没有这个问题的,但很多时候我们自己的设备都升级到了iOS9.3.X系统,导 ...
- 将自己库添加Cocoapods支持
给库添加Cocoapods支持, 使这个工具使用起来更加方便, 更好的使用Cocoapods, 助力iOS程序开发, 下面进入正题, 想要实现这个过程, 绝对不虚此读. 首先写好一个要添加Cocoap ...
- net-snmp源码VS2013编译添加加密支持(OpenSSL)
net-snmp源码VS2013编译添加加密支持(OpenSSL) snmp v3 协议使用了基于用户的安全模型,具有认证和加密两个模块. 认证使用的算法是一般的消息摘要算法,例如MD5/SHA等.这 ...
- net-snmp源码VS2013编译添加加密支持(OpenSSL)(在VS里配置编译OpenSSL)
net-snmp源码VS2013编译添加加密支持(OpenSSL) snmp v3 协议使用了基于用户的安全模型,具有认证和加密两个模块. 认证使用的算法是一般的消息摘要算法,例如MD5/SHA等.这 ...
- Auty自动化测试框架第六篇——垃圾代码回收、添加suite支持
[本文出自天外归云的博客园] 垃圾代码回收 添加脚本恢复机制,因为框架会自动生成一些代码,如果代码生成后出现问题导致代码没有正常删除掉,则会造成代码垃圾,在auty目录添加recovery.py文件: ...
- 为python-sproto添加map支持
上个月太忙了,做完这个修改还没写博客,现在补一下.. 之前使用protobuf做协议打包的时候,经常会有个痛点,没法用具体数据的值作为key来索引数据.比如现在客户端上传了造兵协议,协议大概长这样: ...
随机推荐
- MySQL 数据库通过日志恢复
http://blog.csdn.net/hanxin1987216/article/details/5976856 要想从二进制日志恢复数据,你需要知道当前二进制日志文件的路径和文件名.一般可以从选 ...
- 项目自动化建构工具gradle 入门2——log4j输出helloWorld
上一章节呢,有一个能跑的程序了.但是对做工程的人来说,用日志输出感觉比用System.out要有档次一点.比如使用log4j.直接上例子: 1进入D:\work\gradle\log目录 ,您电脑没 ...
- get方式和set方式提交时乱码
request.setChracterEncoding("utf-8");只对form表单的post提交方式有效. 当使用get提交的时候:
- spring3 循环依赖
循环依赖就是循环引用,就是两个或多个Bean相互之间的持有对方,比如CircleA引用CircleB,CircleB引用CircleC,CircleC引用CircleA,则它们最终反映为一个环.此处不 ...
- Heartbeat使用梳理
在日常的集群系统架构中,一般用到Heartbeat的主要就2种:1)高可用(High Availability)HA集群, 使用Heartbeat实现,也称为"双机热备", &qu ...
- C++基本数据类型总结
一.整形 1.整形有char.short.int.long.long long,这5个也默认为signed XX ; 规则:short至少16位:int至少和short一样:long至少32位,且至少 ...
- [LeetCode] Maximum Depth of Binary Tree 二叉树的最大深度
Given a binary tree, find its maximum depth. The maximum depth is the number of nodes along the long ...
- [LeetCode] Valid Number 验证数字
Validate if a given string is numeric. Some examples:"0" => true" 0.1 " => ...
- [LeetCode] Maximum Subarray 最大子数组
Find the contiguous subarray within an array (containing at least one number) which has the largest ...
- H5是什么,CSS3又是什么?
经常有客户咨询说你们会做H5吗,就像这个,拿过来一看,一个上下滑动的贺卡,这已经成为了大部分人对H5的理解,甚至很多大公司都推出了制作这种动画的工具,可以快速生成此类页面.(其实,这就用到了一些CSS ...