NYCPHP Meetup

NYPHP.org

[nycphp-talk] filewhatevertime for Windows folder

David Krings ramons at gmx.net
Tue Jun 19 10:25:55 EDT 2007


pyurt wrote:
> David 	
> 
> Can you provide a little more detail. 
> How are you testing file time? 
> What OS? 
> Are you getting increasing times from the files with just the wrong time or
> complete random values? 
> 
> Paul 

I tested this on XP and the reported times are always the same.


This is what I used to have as code:

// Clean up stale login data
// Make time stamp for 24 hours in the past
$timestamp = time() - 24 * 60 * 60;

// Read temp dir
if ($handle = 
opendir($_SESSION['filepathtoroot'].DIRECTORY_SEPARATOR."temp")) {
     while (false !== ($file = readdir($handle))) {
         if ($file != "." && $file != "..") {
             // Check file time of directory
             $filetime = 
fileatime($_SESSION['filepathtoroot'].DIRECTORY_SEPARATOR."temp".DIRECTORY_SEPARATOR.$file);
             if ($filetime < $timestamp) $oldsessionids[] = $file;
         }
     }
     closedir($handle);
}


The problem was that opening the directory for read changes the access 
time of all subdirectories. I changed the code to use filemtime and that 
  appears to work better and gives sufficient accuracy for my needs. I 
now have to add some code at significant points where the script checks 
when the login occured so that I don't end up writing to a directory 
that some other login just deleted. That should be easy enough by 
checking against my login table and forcing everyone to login again when 
their login was more than 24 hours ago.

I may make this more lenient/configurable as I can see some value for 
allowing someone to hanng around in the system for more than 24 hours 
assuming that the session lives that long, which I doubt.

Does anyone know for how long session data is kept when idling?


David



More information about the talk mailing list