Forum Moderators: coopster

Message Too Old, No Replies

Odd time issue with filemtime()

Functionality problem with filemtime

         

clype33

9:43 pm on Feb 10, 2005 (gmt 0)

10+ Year Member



I am a newb I have to admit at this programming lark (I have tried various languages in the past but can't seem to find my way round them, but for once I feel I am getting somewhere with php and have written my first fully functional program that does something useful (well for me and my workmates anyway!).

The purpose of the program is to read some logfiles we import to our webserver and parse out some lines which are displayed on a website (near real time stats essentially)
All this works fine but one part of my output does not read as I would expect.
When my script reads each logfile it also picks up the date and time of the last modified time of the file. As these logs are replaced every 10 minutes its important I can see when the latest stats are essentially. I use the filemtime() function.
The basic funtionality seems to work but the time I get out is odd. I have broken my code down to a simple read the file time and print it on screen but this returns the same time.
If I telnet to the server and read the last modded time it says (at present 10:22) But my php script outputs 10:02. This seems to stay like this for an hour then outputs 11:02.
Its like it only sees hourly changes (always at 2 mins past the hour) I thought it might be some sort of cacheing so have called clearstatcache() in my script but this makes no difference. What time is this showing me here then if its not the true system file modification time? any ideas?
I have tried this out on my test server also with the same result- is it a php issue or a server issue? (Apache 2/php4.3.4/ Mandrake Linux 10

jatar_k

9:48 pm on Feb 10, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Welcome to WebmasterWorld clype33,

would you mind posting the stripped down code? Then maybe we can get a better idea where it is possibly going wrong.

clype33

10:24 pm on Feb 10, 2005 (gmt 0)

10+ Year Member



This is a simple bit test script that I used just to confirm the dates and times I was getting in my array that I use in my final code agreed with the straight reading dates and times from the server so its nothing fancy- but the problem is the same.
<?php
//declare a variable which identifies the file names and locations
$logtan="gsnlogs/ci_tanb.log";
$logbir="gsnlogs/ci_bir.log";
$logbsw="gsnlogs/ci_bsw.log";
$logliv="gsnlogs/ci_liv.log";
$logenf="gsnlogs/ci_enf.log";
$logrdg="gsnlogs/ci_rdg.log";
$loggnw="gsnlogs/ci_gnw.log";

print "filemtime<br>";
$create = filemtime ($logtan);
$time = date("H:m d/m/y", $create);
print $time. "<br>";
$create = filemtime ($logbir);
$time = date("H:m d/m/y", $create);
print $time. "<br>";
$create = filemtime ($logbsw);
$time = date("H:m d/m/y", $create);
print $time. "<br>";
$create = filemtime ($logliv);
$time = date("H:m d/m/y", $create);
print $time. "<br>";
$create = filemtime ($logenf);
$time = date("H:m d/m/y", $create);
print $time. "<br>";
$create = filemtime ($logrdg);
$time = date("H:m d/m/y", $create);
print $time. "<br>";
$create = filemtime ($loggnw);
$time = date("H:m d/m/y", $create);
print $time. "<br>";
clearstatcache();
?>

clype33

8:02 pm on Mar 1, 2005 (gmt 0)

10+ Year Member



Ha ha
well no one noticed it- the problem was sussed though it was an eagle eyed friend that spotted the issue. My date formatting was wrong- I originallly formatted the date function to give a full date print out on the page ie HH:mm DDMonYYYY
In the process of shortening this I somehow managed to male the time stamp read H:m instead of H:i
this meant it looked like the file time was not changing every ten minutes- it only changed on the hour and the minutes when the month changed (m = month numeric!)
We noticed this morning as its March and all the file stamps updated to 03 in stead of 02!