Filemtime/cachetime 我哪里出错了?

发布于 2024-09-09 09:41:44 字数 438 浏览 8 评论 0原文

我想做的是检查图像的年龄,如果它超过 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

傲性难收 2024-09-16 09:41:45

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

少年亿悲伤 2024-09-16 09:41:45

您还使用 echo('radartest.php'); 不应该是 include('radartest.php'); 吗?

IE。

<?php
$imagename='./radar/auck0.png';
$cachetime = 3600;
    //Start the caching of the images........
    if (file_exists($imagename) && (filemtime($imagename) + $cachetime) > time()) {
          include ("radartest.php");
        } else {
  null; //do nothing
}

?>

Also you're using echo('radartest.php'); shouldn't that be include('radartest.php'); ?

ie.

<?php
$imagename='./radar/auck0.png';
$cachetime = 3600;
    //Start the caching of the images........
    if (file_exists($imagename) && (filemtime($imagename) + $cachetime) > time()) {
          include ("radartest.php");
        } else {
  null; //do nothing
}

?>

瑕疵 2024-09-16 09:41:45

不确定是否可以是运算符优先级。您使用的“and”的优先级低于 &&
尝试将表达式括起来以强制优先:

if ((file_exists($imagename)) && ((filemtime($imagename) + $cachetime) > time())) {

Not sure if it could be operator precedence. You're using "and" which is lower precedence than &&
Try bracketing your expressions to force precedence:

if ((file_exists($imagename)) && ((filemtime($imagename) + $cachetime) > time())) {
你是我的挚爱i 2024-09-16 09:41:45

看起来效果不错....

<?php
$cache_file = './radar/auck0.png';
$cache_life = '3600'; //caching time, in seconds
$filemtime = @filemtime($cache_file);  // returns FALSE if file does not exist
if (!$filemtime or (time() - $filemtime >= $cache_life)){
          include("wxrain.php");
        } else {
        null; //do nothing
}
?>

Seems to work well....

<?php
$cache_file = './radar/auck0.png';
$cache_life = '3600'; //caching time, in seconds
$filemtime = @filemtime($cache_file);  // returns FALSE if file does not exist
if (!$filemtime or (time() - $filemtime >= $cache_life)){
          include("wxrain.php");
        } else {
        null; //do nothing
}
?>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文