开启辅助访问 切换到宽版

精易论坛

 找回密码
 注册

QQ登录

只需一步,快速开始

用微信号发送消息登录论坛

新人指南 邀请好友注册 - 我关注人的新帖 教你赚取精币 - 每日签到


求职/招聘- 论坛接单- 开发者大厅

论坛版规 总版规 - 建议/投诉 - 应聘版主 - 精华帖总集 积分说明 - 禁言标准 - 有奖举报

查看: 1354|回复: 0
收起左侧

[js/PHP求助] 求帮忙修改下PHP代码

[复制链接]
结帖率:73% (36/49)
发表于 2019-11-27 19:45:01 | 显示全部楼层 |阅读模式   广西壮族自治区柳州市
把缓存页面的代码去掉,但不影响正常调用现有的缓存数据   
应该把那部分删掉呢?
【其调用的是 :cacheData/xxx/a864452.txt   txt里是html页面缓存的代码】

<?php

class dirCache {
private $_unitNum = 999;
private $_unitFloor = 3;
private $_pix = '_';
private $_now = 0;
public $baseDir = '';
public $dirMode = 0777;
public function __construct($baseDir = null) {
if ($baseDir) {
$this->baseDir = $baseDir;
}else {
$this->baseDir = dirname(__FILE__) .DIRECTORY_SEPARATOR .'cacheData';
}
if ($_SERVER['REQUEST_TIME']) {
$this->_now = $_SERVER['REQUEST_TIME'];
}else {
$this->_now = time();
}
}
public function isExists($id,$timeout = 0,$isCreate = false) {
$file = $this->hashId($id);
if (!is_file($file)) {
if (is_file($file .'.lock')) {
return 'LOCKED';
}
return false;
}
$timefun = $isCreate ?'filectime': 'filemtime';
if ($timeout &&$timefun($file) +$timeout <$this->_now) {
return false;
}
return true;
}
public function set($id,$data = null) {
return $this->_writeFile($this->hashId($id),$this->_encode($data));
}
public function get($id,$lockread = false) {
return $this->_decode($this->_readFile($this->hashId($id),$lockread));
}
public function del($id) {
return $this->_deleteFile($this->hashId($id));
}
public function hashId($id) {
if (!is_numeric($id)) {
$id = $this->enId($id);
$notNum = 'a';
}
$id = $tid = $id;
$hash = '';
$pow = 0;
for ($i = $this->_unitFloor;$i ;$i--) {
$pow = pow($this->_unitNum,$i);
$unit = floor($tid / $pow);
if ($unit >$this->_unitNum) {
$unit = $this->_unitNum;
}
$hash .= $this->_pix .$unit .DIRECTORY_SEPARATOR;
$tid = $tid -$unit * $pow;
}
unset($pow,$tid,$unit,$i);
return $this->baseDir .DIRECTORY_SEPARATOR .$hash .($notNum) .$id .'.txt';
}
public function enId($data) {
return sprintf('%011u',crc32($data));
}
private function _encode($data) {
$array = array('source'=>$data);
return '<?php die(\'Cache Page by dirCache.\') ?>'.serialize($array);
}
protected function _decode($data) {
$array = unserialize($data);
return $array['source'];
}
protected function _writeFile($file,$data) {
$dir = dirname($file);
if (!is_dir($dir)) {
mkdir($dir,$this->dirMode,true);
}
if (!is_file($file) &&is_file($file .'.lock'))
{
return false;
}
$mqr = get_magic_quotes_runtime();
set_magic_quotes_runtime(0);
$re = @ file_put_contents($file,$data,LOCK_EX);
set_magic_quotes_runtime($mqr);
return $re;
}
protected function _readFile($file,$lockread = false) {
if (!is_file($file))
{
if (!$lockread) {
return false;
}
$file .= '.lock';
if (!is_file($file)) {
return false;
}
}
return file_get_contents($file,null,null,39);
}
protected function _deleteFile($file) {
if (is_file($file))
{
return unlink($file);
}
return false;
}
public function lock($id) {
$file = $this->hashId($id);
if (!is_file($file) &&is_file($file .'.lock'))
{
return true;
}
return rename($file,$file .'.lock');
}
public function unlock($id) {
$file = $this->hashId($id);
if (is_file($file) &&!is_file($file .'.lock'))
{
return true;
}
return rename( $file .'.lock',$file);
}
}
?>


您需要登录后才可以回帖 登录 | 注册

本版积分规则 致发广告者

发布主题 收藏帖子 返回列表

sitemap| 易语言源码| 易语言教程| 易语言论坛| 易语言模块| 手机版| 广告投放| 精易论坛
拒绝任何人以任何形式在本论坛发表与中华人民共和国法律相抵触的言论,本站内容均为会员发表,并不代表精易立场!
论坛帖子内容仅用于技术交流学习和研究的目的,严禁用于非法目的,否则造成一切后果自负!如帖子内容侵害到你的权益,请联系我们!
防范网络诈骗,远离网络犯罪 违法和不良信息举报电话0663-3422125,QQ: 793400750,邮箱:wp@125.la
网站简介:精易论坛成立于2009年,是一个程序设计学习交流技术论坛,隶属于揭阳市揭东区精易科技有限公司所有。
Powered by Discuz! X3.4 揭阳市揭东区精易科技有限公司 ( 粤ICP备12094385号-1) 粤公网安备 44522102000125 增值电信业务经营许可证 粤B2-20192173

快速回复 返回顶部 返回列表