php缓存的问题! 假如说有一个a.php文件,这个程序是采集其他网站的信息,当用户访问网页的时候会用ajax触发这个php程序进行采集,但是我不想让用户每次来的时候都进行采集,规定1个小时内的内容不变,一个小时后才进行采集,这个功能怎么实现?要进行缓存么?缓存文件用什么格式的?文件内的内容该怎么写?求大神们给个思路! 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 问题在于你如何知道内容没有改变?如果目标是纯静态页面,是可以用 get_headers 获取最后修改时间来判断一下如果目标是动态页面,你不取回来比较,就不知道是否改变了 <!DOCTYPE html><body> <div id="msg"></div> <script>var xmlhttp;if(window.ActiveXObject){ xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");}else{ xmlhttp=new XMLHttpRequest();}xmlhttp.open("POST", "a.php", true); xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); xmlhttp.send("data=1"); xmlhttp.onreadystatechange = function(){ if(xmlhttp.readyState === 4 && xmlhttp.status === 200){ document.getElementById("msg").innerHTML=xmlhttp.responseText; } } </script></body></html><?php$time=time();$time2=file_get_contents("time.dat");if($time-3600>$time2){ file_put_contents("time.dat",$time); $con=file_get_contents("http://www.baidu.com"); file_put_contents("content.dat",$con);}else{ $con=file_get_contents("content.dat");}echo $con;?> 借助liux的 crontab或者生成一个锁文件 判断这个文件生成时间与当前时间是否相距1小时了 这硬件是? 求教:为何在linux下无法用php创建新文件 关于页面跳转的问题 base64乱码 php5.2.6不能加载openssl模块问题 单击提交按钮有错误返回时,表单上已填写密码被清除 网站上放个计数器,和一个在线人数计数器,是用PHP还是用ASP? 请教,SQL语句里如何运行PHP函数对查询的结果进行限制? 关于session的认证问题。 js 算法 转php 轻松解决Warning: Cannot modify header information – headers already sent by…… php安装包如何做成和软件安装类似的步骤
如果目标是纯静态页面,是可以用 get_headers 获取最后修改时间来判断一下
如果目标是动态页面,你不取回来比较,就不知道是否改变了
<body>
<div id="msg"></div>
<script>
var xmlhttp;
if(window.ActiveXObject)
{
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
else
{
xmlhttp=new XMLHttpRequest();
}
xmlhttp.open("POST", "a.php", true);
xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
xmlhttp.send("data=1");
xmlhttp.onreadystatechange = function(){
if(xmlhttp.readyState === 4 && xmlhttp.status === 200){
document.getElementById("msg").innerHTML=xmlhttp.responseText;
}
}
</script>
</body>
</html><?php
$time=time();
$time2=file_get_contents("time.dat");
if($time-3600>$time2){
file_put_contents("time.dat",$time);
$con=file_get_contents("http://www.baidu.com");
file_put_contents("content.dat",$con);
}else{
$con=file_get_contents("content.dat");
}
echo $con;
?>
或者生成一个锁文件 判断这个文件生成时间与当前时间是否相距1小时了