怎么样刷新缓存文件 怎么样刷新缓存文件我在一个循环里写了 判断一下(当数组a的长度小于1时就执行一次) 写进缓存的操作,反之,不执行写进缓存的操作。问题就出来这儿当执行到 数组a 小于1时,就写一次缓存b.txt 然后我立既读这个缓存b.txt文件(我用记事本打开b.txt,可以得到正确的内容),而得到的是一个错误的结果 还是数组a的值,并没有变化,只有当我在执行一下这个方法时,才能读到这个b.txt 文件。我在该怎么做?才能解决这个问题。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 $urlArray = cache::get('tuangouBaiduType');echo "<pre>a";print_r($urlArray); //$urlArray 为 空 if(count($urlArray)<=1){ cache::init("php"); $type = array('a','b','c','d'); cache::set('tuangouBaiduType',$type); } cache::init("php"); $urlArray = cache::get('tuangouBaiduType'); echo "<pre>d";print_r($urlArray); // $urlArray的内容为空 并不是 'a','b','c','d'大约就是这样的 $urlArray = cache::get('tuangouBaiduType');echo "<pre>a";print_r($urlArray); //$urlArray 为 空 if(count($urlArray)<=1){cache::init("php");$type = array('a','b','c','d');cache::set('tuangouBaiduType',$type); }cache::init("php"); $urlArray = cache::get('tuangouBaiduType'); echo "<pre>d";print_r($urlArray); // $urlArray的内容为空 并不是 'a','b','c','d'大约就是这样的 读之前,使用fclose了吗,另外把问题简单化,把代码从项目中提练出来,(提练本身也是分析问题),然后再测试. 算我没说,你先看下cache类吧。没人知道它怎么实现缓存了 读他是用的file_put_contents($this->getFile($id),'<?php return array('.$expire.','.var_export($value, true).');',LOCK_EX); public function set($id,$value,$expire=0) {//echo "<pre>";echo "a";print_r($value);exit(); file_put_contents($this->getFile($id),'<?php return array('.$expire.','.var_export($value, true).');',LOCK_EX); } public function get($id) { $cFile = $this->getFile($id); if (file_exists($cFile)) { $data = include $cFile; if(SYSTIME < $data[0] || $data[0] == 0) { return $data[1]; }else { @unlink($cFile); } } return false; } 问题不出在文件读写,应该检查整个逻辑当然也不排除你不能通过下面的测试例file_put_contents('zzz', 'a');$s = file_get_contents('zzz');echo $s;$fp = fopen('zzz', 'w');fwrite($fp, 'b');$fp = fopen('zzz', 'r');echo fgets($fp);ab <?php file_put_contents("1.txt","aabbcc",LOCK_EX);$a = file_get_contents('1.txt');echo $a;?>这这样写了一个都得行 php正则匹配汉字结尾的字符串 PHP Version 4.3.2,偶尔取不到post的,为什么呢? PHP的弱弱问题。。。 请教个语法问题 请大家帮我想想,附加码不能显示是怎么回事呀? 请问如何用php往sqlserver里存储图片? 请大家来看看这段代码............ -_-_-_-_-_-_-提高PHP效率80%的软件_-_-_-_-_-_-_-_-_ php网页存在乱码,求各位解决,谢谢了 PHP函数内while 循环无效 同一文件两种方式访问效果不一样 php调用动态库问题(php扩展)
echo "<pre>a";print_r($urlArray); //$urlArray 为 空
if(count($urlArray)<=1){
cache::init("php");
$type = array('a','b','c','d');
cache::set('tuangouBaiduType',$type);
}
cache::init("php");
$urlArray = cache::get('tuangouBaiduType');
echo "<pre>d";print_r($urlArray); // $urlArray的内容为空 并不是 'a','b','c','d'大约就是这样的
echo "<pre>a";print_r($urlArray); //$urlArray 为 空
if(count($urlArray)<=1){
cache::init("php");
$type = array('a','b','c','d');
cache::set('tuangouBaiduType',$type);
}
cache::init("php");
$urlArray = cache::get('tuangouBaiduType');
echo "<pre>d";print_r($urlArray); // $urlArray的内容为空 并不是 'a','b','c','d'大约就是这样的
public function set($id,$value,$expire=0)
{
//echo "<pre>";echo "a";print_r($value);exit();
file_put_contents($this->getFile($id),'<?php return array('.$expire.','.var_export($value, true).');',LOCK_EX);
}
public function get($id)
{
$cFile = $this->getFile($id);
if (file_exists($cFile))
{
$data = include $cFile;
if(SYSTIME < $data[0] || $data[0] == 0)
{
return $data[1];
}else
{
@unlink($cFile);
}
}
return false;
}
当然也不排除你不能通过下面的测试例file_put_contents('zzz', 'a');
$s = file_get_contents('zzz');
echo $s;$fp = fopen('zzz', 'w');
fwrite($fp, 'b');
$fp = fopen('zzz', 'r');
echo fgets($fp);ab
<?php file_put_contents("1.txt","aabbcc",LOCK_EX);
$a = file_get_contents('1.txt');
echo $a;
?>
这这样写了一个都得行