News Feed
Sections




News Archive
Looking for more information on how to do PHP the right way? Check out PHP: The Right Way

Larry Garfield's Blog:
readfile() not considered harmful
May 04, 2012 @ 09:51:38

In this new post to his blog Larry Garfield tries to dispel a common misconception in the PHP development world - that the readfile function should be considered harmful and can cause memory issues in your code.

If you're like me, you've probably read a dozen or two articles about PHP performance in your career. Many of them are quite good, but some are simply flat out wrong, or misinformed. One of the old truisms that has been repeated for as long as I can recall is "don't use readfile() if you have big files, because it reads the whole file into memory and your server will explode." [...] There's just one problem with that age-old truism: It's not true.

He created some benchmarks to illustrate the differences between several of the common methods for working with files via the fread, fpassthru, stream_copy_to_stream and of course readfile. He reports the results based on the runtime and the peak memory usage and noted, ironically, that while the times varied slightly, the memory consumption was exactly the same for all of the approaches. Since there's no real reason not to use "readfile", he looks at three reasons why there might be this stigma attached to it (including the issues that could come up with output buffering enabled).

0 comments voice your opinion now!
readfile file handling harmful dispel myth benchmark memory


blog comments powered by Disqus

Similar Posts

Jani Hartikainen's Blog: Sending files better: Apache mod_xsendfile and PHP

Zend Developer Zone: Desktop Image Uploaders Using Adobe AIR and JavaScript

PHPit.net: Handling dates and times in PHP & MySQL

Kevin Schroeder: More - The file system is slow

Secunia.com: phpChess Community Edition Multiple File Inclusion


Community Events

Don't see your event here?
Let us know!


symfony2 framework laravel api interview release language podcast performance conference series application php7 opinion community introduction library configure example install

All content copyright, 2015 PHPDeveloper.org :: info@phpdeveloper.org - Powered by the Solar PHP Framework