您现在的位置是:首页 > cms教程 > phpcms教程phpcms教程
phpcms添加memcache支持的代码示例
映易2025-05-21phpcms教程已有人查阅
导读2,修改phpcms/libs/functions/globl.func.php 文件的四个函数3,修改phpcms/libs/classes/cache_memcache.class.php
<color=rgba(0,]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>";
}
}
}
?>
本文标签:
很赞哦! ()
相关教程
图文教程
phpcmsv9全站点击量排行代码分享
phpcmsv9全站点击量排行代码。后台phpcms/modules/content/classes/content_tag.class.php
PHPCMSv9.6.0任意文件上传漏洞getshell
phpstudy本地搭建phpcmsapache2.4.39+php5.3.29+mysql8.0.12首先需要在1.txt中写入一句话木马这里将会得到一句话木马文件的地址,就可以成功getshell了
phpcms本地安装怎么打开首页
phpcms打开首页的方法:首先下载并安装好phpcms软件;然后在浏览器的地址栏中输入地址“http://127.0.0.1”或者“http://localhost”即可打开首页并访问。
phpcmsv9表单实现问答咨询功能的方法
phpcms v9的留言板插件可以安装留言板,做问答咨询,那样的话有很多东西需要修改,也有人发现phpcms v9有个表单向导功能,只能留言,不能回复,今天仿站网
相关源码
-
pbootcms模板(PC+WAP)微信小程序开发公司网站本模板为微信小程序开发代理、软件开发公司等企业设计,基于PbootCMS内核开发,支持PC+WAP双端响应式布局,数据实时同步,适用于多行业快速建站。查看源码 -
(自适应响应式)HTML5幕墙装饰工程建筑装修公司pbootcms模板下载基于PbootCMS开发的响应式模板,为幕墙工程、建筑装饰企业设计,通过数字化展示提升企业专业形象与项目展示能力。结构化数据标记增强项目案例收录,智能URL路由优化,支持每个工程案例独立设置关键词与描述查看源码 -
pbootcms模板(PC+WAP)火锅加盟餐饮美食类带留言源码基于PbootCMS内核深度开发,为火锅、餐饮品牌打造的营销型解决方案。采用红色主题传递行业活力,实现PC与WAP端适配。查看源码 -
(自适应)APP应用软件落地页单页推广页网站模板下载基于PbootCMS内核开发的响应式单页模板,为企业产品展示、服务推广等应用场景设计。通过简洁直观的视觉布局与高效的技术架构,帮助用户快速构建专业级落地页面,实现移动端与PC端数据实时同步展示。查看源码 -
帝国cms7.5品牌连锁店招商加盟商机网站模版源码本模板为招商加盟、创业投资、品牌连锁等商业领域设计,采用帝国CMS7.5内核构建,整体风格简洁大气,突出商业信任感与专业度,适合各类招商加盟项目展示、品牌连锁店宣传等商业应用场景。查看源码 -
(自适应响应式)黑色LED显示屏户外广告屏网站源码下载这是一款基于PbootCMS内核开发的响应式网站模板,专门为LED显示屏及户外广告行业打造。模板适配各类显示设备,帮助企业快速搭建专业官网,展示产品与服务优势,有效提升品牌形象。查看源码
| 分享笔记 (共有 篇笔记) |
