您现在的位置是:首页 > 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>";
}
}
}
?>

本文标签:

很赞哦! ()

相关源码

  • pbootcms模板(自适应手机版)红色响应式单位机构类网站自适应响应式单位机构网站模板 | PbootCMS内核开发为机构组织设计的响应式网站模板,采用PbootCMS内核开发,支持一键替换行业内容,满足多元化场景需求。查看源码
  • 宽屏自适应搬家家政快递物流公司网站模板该宽屏大气的响应式网站模板专为搬家公司、家政服务及物流快递企业设计,基于PbootCMS内核开发,通过自适应布局确保手机、PC等多终端体验一致,助力企业高效构建专业在线服务平台。查看源码
  • 帝国CMS7.5养生生活健康网模板完整带会员中心可封装APP本套模板为生活服务类网站设计,适用于两性健康、减肥瘦身、生活资讯等领域。采用帝国CMS7.5核心开发,结构清晰合理,视觉体验舒适,能够有效满足相关行业的建站需求。查看源码
  • 自适应车行汽车租赁二手车行业企业网站模板为汽车租赁与二手车交易场景深度优化,采用PbootCMS内核开发,聚焦车辆展示、租赁流程与服务介绍三大核心模块。响应式布局确保PC与移动端数据实时同步,后台一键管理车辆信息查看源码
  • 响应式艺考培训学校机构pbootcms模板html5源码基于PbootCMS免费开源内核开发,为艺考培训学校与艺术机构设计,替换图文即可快速适配全行业需求。响应式布局兼容手机/PC端,数据实时同步,运维效率提升300%。查看源码
  • WordPress主题模板主题巴巴/博客X主题源码免费下载博客X主题专注于内容创作领域,为博客、资讯类网站提供专业的内容展示解决方案。该模板采用精心设计的布局结构,能够有效提升内容的可读性和用户停留时间。查看源码
分享笔记 (共有 篇笔记)
验证码:

本栏推荐