|
Posted by Richard Davey on 10/14/05 14:42
Hi Ruben,
Friday, October 14, 2005, 12:29:09 PM, you wrote:
> What can I do to make faster opening files?
> **************************************************************
> Source code:
> if(file_exists($filename)){
> $modified_date=filemtime($filename);
> if(time()<($modified_date+1 * 24 * 60 * 60)){
> $handle = fopen($filename, "r");
> $contents = fread($handle, filesize($filename));
> fclose($handle);
> echo $contents;
> }
> }
> **************************************************************
You could try using file_get_contents instead of fopen/fread/fclose
and see if that makes any difference.
Also possibly try stat instead of filemtime? It would at least cache
the file stats on the 2nd run through, etc.
At the end of the day though any hard drive operation is going to be
relatively slow. Perhaps there is another way to do what you need that
avoids opening all the files? At the moment you appear to be checking
every files modified time then opening it. Perhaps you could get back
a directory listing instead and parse the modified time from this,
rather than check every single file?
Cheers,
Rich
--
Zend Certified Engineer
http://www.launchcode.co.uk
[Back to original message]
|