Reply to Re: [PHP] OPTIMIZING - The fastest way to open and show a file

Your name:

Reply:


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]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация