Filemtime/cachetime 我哪里出错了?
我想做的是检查图像的年龄,如果它超过 60 分钟,则运行另一个 php 页面来获取图像,否则如果小于 60 分钟,则不执行任何操作......
该脚本不会打开第二页(radartest.php)并运行它来更新图像,因此需要一个命令来告诉它作为脚本运行。
<?php
$imagename='./radar/auck0.png';
$cachetime = 3600;
//Start the caching of the images........
if (file_exists($imagename) and filemtime($imagename) + $cachetime > time()) {
echo("radartest.php");
} else {
null; //do nothing
}
?>
What I am trying to do is check the age of an image, if its older than 60 minutes then run another php page to fetch images otherwise do nothing if less than 60 minutes old....
The script isn't opening the 2nd page (radartest.php) and running it to update the images, so need a command to tell it to run as a script please.
<?php
$imagename='./radar/auck0.png';
$cachetime = 3600;
//Start the caching of the images........
if (file_exists($imagename) and filemtime($imagename) + $cachetime > time()) {
echo("radartest.php");
} else {
null; //do nothing
}
?>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
filemtime 返回的结果被缓存。
这只是一个猜测,但如果您过于频繁地使用这段代码,您可能必须使用clearstatcache函数:http://php.net/manual/en/function.clearstatcache.php
Result returned by filemtime is cached.
It's only a guess, but if you're using this piece of code too frequently you may have to use the clearstatcache function : http://php.net/manual/en/function.clearstatcache.php
您还使用
echo('radartest.php');
不应该是include('radartest.php');
吗?IE。
?>
Also you're using
echo('radartest.php');
shouldn't that beinclude('radartest.php');
?ie.
?>
不确定是否可以是运算符优先级。您使用的“and”的优先级低于 &&
尝试将表达式括起来以强制优先:
Not sure if it could be operator precedence. You're using "and" which is lower precedence than &&
Try bracketing your expressions to force precedence:
看起来效果不错....
Seems to work well....