|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #41859 Low throughput with readfile/fpassthru
Submitted: 2007-06-29 22:10 UTC Modified: 2007-07-13 01:00 UTC
Avg. Score:3.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:0 (0.0%)
Same OS:0 (0.0%)
From: champs dot name at gmail dot com Assigned:
Status: No Feedback Package: Performance problem
PHP Version: 5.2.3 OS: Windows Server 2003/IIS6
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Bug Type:
From: champs dot name at gmail dot com
New email:
PHP Version: OS:


 [2007-06-29 22:10 UTC] champs dot name at gmail dot com
With a client using a 10Mbps connection, it is possible to saturate the pipe using print(fread(...)) in chunks of 32K or larger, but the throughput of fpassthru() and readfile() is consistently ~1/3 of that speed.  On the other side of the coin, a client with sub-Mbit DSL is not able to complete 100MB downloads at all, unless readfile/fpassthru() is used.

This has been tested in different orders, at different times of day, and on different, non-consecutive days.

Reproduce code:
if ($file = fopen($path, $mode)) {
	$chunk_size = 32;

	while(!feof($file)) {

		print(fread($file, $chunk_size * 1024));
		if (connection_status() == 0) {
		else {


Expected result:
Similar throughput if while() block is replaced with "fpassthru($file)" or "readfile($path)".

Actual result:
File is served at over 900kB/s with fread(), less than 300kB/s with fpassthru/readfile().


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2007-06-30 11:58 UTC] judas dot iscariote at gmail dot com
You have to choose between readfile() and your code, readfile is "designed" to be fast AND use few memory.

The best way you have to do this is simple. DO NOT serve files through PHP :) use mod_secdownload and/or X-SendFile with lighttpd...with apache use mod_auth_token and/or mod_sendfile to make the webserver itself to serve the file
 [2007-07-03 06:54 UTC]
Did you try to reproduce on *nix ?
 [2007-07-03 17:34 UTC] champs dot name at gmail dot com
This does not appear to be a problem with Apache 2 + PHP5 + Linux, performance numbers are within 5% of eachother.

While I cannot test the Apache + Win32 combination, I can look at the PHP source to say that it does not appear to be something in the ISAPI-specific code, although it may have something to do with the affected code's interaction with IIS.
 [2007-07-05 13:56 UTC]
We don't have any win32 developers at the moment and I would appreciate if you provide any info you can gather in order to help us to understand the issue.
 [2007-07-13 01:00 UTC] php-bugs at lists dot php dot net
No feedback was provided for this bug for over a week, so it is
being suspended automatically. If you are able to provide the
information that was originally requested, please do so and change
the status of the bug back to "Open".
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu May 30 06:01:31 2024 UTC