Re: Files passing through
| From: | Jasper Bryant-Greene | Date: | Tue, 23 Aug 2005 09:19:02 +0000 |
| Subject: | Re: Files passing through | ||
| References: | 1 2 3 4 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-221154@lists.php.net to get a copy of this message | ||
Richard Lynch wrote:
On Tue, August 23, 2005 12:48 am, Jasper Bryant-Greene wrote:I benched this with a 100 MiB text file (largest I could find at short notice). Buffer used for fread() calls was 2 KiB as above. Values are averaged over 100 runs (I would have liked to do more, but I don't have time). All values are to 4 significant figures. Assigning to a variable and then printing took 0.5206 sec Printing directly without assigning to any variable took 0.5178 sec readfile() took 0.4632 sec print(file_get_contents()) took 0.7037 sec Therefore, readfile() is the fastest, print(file_get_contents()) most definitely the slowest, and it makes ****-all difference between assigning the buffer to a variable and not, at least for files around 100 MiB. JasperKim Steinhaug (php list) wrote:You're not missing anything, but a 2 K string buffer assignment/print is probably not gonna save much... Benchmark it both ways and see.I'm using this method, works fine with 50mb+ files : if( $fd = fopen ($filepath, 'r')){Is there a reason why you assign the output of fread() to a variable and then print it? Why not just: print(fread($fd, 2048)); which would be faster because it doesn't need to assign to a variable, wouldn't it? Maybe I'm missing something..while(!feof($fd)) { $buffer = fread($fd, 2048); print $buffer; } fclose ($fd); exit;}