|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #16303 file() MUCH faster than fsockopen() + fgets() but we should be able to set th
Submitted: 2002-03-27 01:55 UTC Modified: 2003-02-06 22:24 UTC
From: jpaulomf at terra dot com dot br Assigned:
Status: Not a bug Package: Feature/Change Request
PHP Version: 4.1.1 OS: Linux
Private report: No CVE-ID: None
 [2002-03-27 01:55 UTC] jpaulomf at terra dot com dot br
When tring to open a file for remote edition like:

$file = file("");

Whe can't set the headers.
And why one would like to?

1 - Readfile throws the content to std out.
2 - fsockopen takes too much time to do the same:

$sck = fsockopen($host,$port,&$errno,&$errstr);
while(!feof($sck)) {
   $result .= fgets($sck,128);
This will take about 300-400% more time compared with file() or readfile(). (WHY??? Ive tested the int lenght of fgets() with 2,32,64,128...4096 and it is still very slow: filesizes > 400kb ~ 90-120 sec (@ 256k) when file() does the same in ~ 20-30 sec).

I've not tested cURL yet, but I think PHP should support this w/o 3 parties..

Thanks ppl!


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2002-03-27 09:23 UTC]
I'm not quite sure what you are asking for here;
could you be more specific?
 [2002-03-28 00:40 UTC] jpaulomf at terra dot com dot br
We should able to set the headers sent by file() and fopen-wrappers when the requests are made to outside, like:

$file = fopen("");
 [2002-03-28 00:58 UTC] jpaulomf at terra dot com dot br

$file = file("");
$file = readfile("");

and what I told you before was that the other options we have to send our own defined headers(fsockopen) are too slow. 

What I'm asking is to have the ability to set the headers of file(), readfile() and fopen().
 [2003-02-06 22:24 UTC]
Try using fread() and a large buffer, something like 20000-50000 bytes. This will reduce the number of PHP operations that occur and probably be much closer file() performance. 
As for your request of adding headers to file(), readfile() and so on it is simple not practical as it would break many existing scripts that rely on the lack of headers.
PHP Copyright © 2001-2022 The PHP Group
All rights reserved.
Last updated: Mon May 23 08:05:45 2022 UTC