Using PHP to serve files
Sometimes you need PHP to passthru files instead of using a webserver like you should. Sometimes you need to check permissions; or do other stuff which requires you to make PHP behave like a webserver. So, what is the fastest way to passthru a simple file using no logic? I have been working of several ways of benchmarking this. First; I used Apache Bench to run a PHP file a few hundred times; but the results were too unstable. Sometimes I got 2 requests per second, sometimes I got 30 requests per second using the same settings. So I started looking for a different way of benchmarking. I found a way which was pretty stable. However; the results weren’t really interesting either. I ran all commands 100 times for different file sizes; the only noticeable change was readfile becoming slower as the file size increased (from 2.3 to 3.2 for a 6 Mb file). All other functions (fgets, file_get_contents, fpassthru, fread, readfile) remained constantly at 2.3 seconds. Conclusion is it doesn’t really matter what function you use; the speed difference is negligible.