Welcome to Dream.In.Code
Become a PHP Expert!

Join 150,007 PHP Programmers for FREE! Get instant access to thousands of PHP experts, tutorials, code snippets, and more! There are 1,390 people online right now. Registration is fast and FREE... Join Now!




filemtime

 
Reply to this topicStart new topic

filemtime

lauro
17 Nov, 2006 - 12:50 PM
Post #1

New D.I.C Head
*

Joined: 2 Nov, 2006
Posts: 3


My Contributions
Hello guys,
I know the basics of PHP, but have one minor problem, where I have not found a good solution myself.
I have a script, which fetches external data, processes it and finally saves the
processed data in a text file. The data is updated only if a certain time has passed from the previous update. I am using filemtime($file) and time() for comparison and it works.
So far everything OK. But after the data has been updated I show the data on my webpage and at the bottom of all information I am trying to display the time for next available update, again using filemtime() function. What happens is that the second filemtime retrieves the original (previous) update time, not the new one. So, it seems the server does not return the right modification right after saving the file. If I make the script to reload the page, the problem is corrected, but I would not want a reload in this case. Any suggestions? I know that writing the saving time into the file itself and using that in the script solves the problem, but that sounds a bit too "heavy".
Thanks in advance,
Lauro

This post has been edited by lauro: 17 Nov, 2006 - 12:51 PM
User is offlineProfile CardPM
+Quote Post

BetaWar
RE: Filemtime
17 Nov, 2006 - 05:02 PM
Post #2

#include <soul.h>
Group Icon

Joined: 7 Sep, 2006
Posts: 2,304



Thanked: 101 times
Dream Kudos: 1275
My Contributions
filetime() i believe gives the time that the file was previously updated. If you want it to tell the next update time then get the filetime() then add a certain number to it so that it changes. I am not sure that this works great or anything but it may work.
User is online!Profile CardPM
+Quote Post

lauro
RE: Filemtime
17 Nov, 2006 - 11:41 PM
Post #3

New D.I.C Head
*

Joined: 2 Nov, 2006
Posts: 3


My Contributions
QUOTE(BetaWar @ 17 Nov, 2006 - 06:02 PM) *

filetime() i believe gives the time that the file was previously updated. If you want it to tell the next update time then get the filetime() then add a certain number to it so that it changes. I am not sure that this works great or anything but it may work.


Thanks for your suggestion. It made me check php.net for filemtime() function.
And the solution was there! Filemtime is one of those file functions, which caches
the information. If the same file is being checked multiple times within a single script, one must use clearstatcache. So my code looks like this now:

CODE

$updated = filemtime($file);
clearstatcache();
....... code, where I update the file, if needed .....

$updated = filemtime($file);


Now the second call of the same function gives a correct result. smile.gif
- Lauro -
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 1/8/09 08:41PM

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter

Live PHP Help!

PHP Tutorials

Reference Sheets

PHP Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month