views:

28

answers:

3

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
}
?>
A: 

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())) {
Mark Baker
Hammerite
Mark Baker
I have changed the complete line, embarrassing thing is that I was checking the image age on the webpage instead of on the server, to my astonishment, I found I'm not actually triggering the 2nd page at all.
Gary
A: 

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
}

?>

Kieran Allen
Have tried require_once, echo, print and include but not triggering the 2nd page at all, also dropped cachetime down to 10 seconds for testing purposes.
Gary
A: 

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
}
?>
Gary