Re: OPTIMIZING - The fastest way to open and show a file

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux