#19971 [Com]: file() function extremally slow

2003-01-24 Thread jamie
 ID:   19971
 Comment by:   [EMAIL PROTECTED]
 Reported By:  [EMAIL PROTECTED]
 Status:   Closed
 Bug Type: *Directory/Filesystem functions
 Operating System: any
 PHP Version:  4.3.0-dev
 New Comment:

Please reopen. 
 
PHP 4.2.2 and 4.2.1 appeared to cause delays as well but   
PHP 4.3.0 made Squirrelmail unusable. phpMyAdmin appeared   
to be affected as well. Downgrading to PHP 4.0.6 resolved   
problem. Not clear if this file() function is culprit, but   
system load remained low and Cyrus and MySQL do not appear   
to be culprit of the application-level slowdown. (Command   
line clients do not experience problems.) NOTE: This does   
NOT appear to be resolved by CVS snapshot as of 2002 01-23,   
which is contrary to above PHP bug!  
  
Additional information:  
Gentoo Linux 1.2, nightly update (gcc 2.95)  
Cyrus IMAPd 2.1.11  
MySQL 3.23.54a  
PHP 4.3.0, 4.2.2, 4.2.1  
SquirrelMail 1.2.10  
phpMyAdmin 2.3.2 (Gentoo rev 1)  
  
Please also see  
http://bugs.gentoo.org/show_bug.cgi?id=14513


Previous Comments:


[2002-10-18 15:40:14] [EMAIL PROTECTED]

This bug has been fixed in CVS.

In case this was a PHP problem, snapshots of the sources are packaged
every three hours; this change will be in the next snapshot. You can
grab the snapshot at http://snaps.php.net/.
 
In case this was a documentation problem, the fix will show up soon at
http://www.php.net/manual/.

In case this was a PHP.net website problem, the change will show
up on the PHP.net site and on the mirror sites in short time.
 
Thank you for the report, and for helping us make PHP better.





[2002-10-18 09:59:58] [EMAIL PROTECTED]

I got the following times from a tests I've run on PHP.
The test involved openning a 2.5 meg binary file 1000 times.
The results are everages of several runs.
 
file_get_contents() - 30.4 seconds (4.3 HEAD)
file() - 99.2 seconds (4.3 HEAD)
file() - 40.3 seconds (4.2.3)

Looks like a VERY  serious performance loss to me, I'd even go as far
as to say this is a critical issue that should be resolved before
release.

For reference perpouses a simple C program that freads() entire file to
memory took only 18.5 seconds to run (1000 runs on the same file).



[2002-10-18 07:04:36] [EMAIL PROTECTED]

fgets() is fast.

yohgaki@dev DEV]$ cat t.php
 setMarker('Start');

$fp = fopen($filename,'r');
for ($i = 0; $i<100; $i++)
  $s = explode("\n", fread($fp, filesize($filename)));
fclose($fp);

$time -> setMarker('fread'); 

for ($i = 0; $i<100; $i++)
  $s = file($filename);
$time -> setMarker('file'); 

for ($i = 0; $i<100; $i++)
  $s = file_get_contents($filename);
$time -> setMarker('file_get_contents'); 

$fp = fopen($filename,'r');
for ($i = 0; $i<100; $i++)
  $s = fgets($fp,filesize($filename));
$time -> setMarker('fgets'); 
fclose($fp);

[yohgaki@dev DEV]$ ./sapi/cli/php  t.php 
-
markertime indexex time  
perct
-
Start 1034942600.41311100   -  
0.00%
-
fread 1034942600.43045000   0.017338991165161  
2.68%
-
file  1034942600.95939400   0.52894401550293  
81.66%
-
file_get_contents 1034942601.04506900   0.085675001144409 
13.23%
-
fgets 1034942601.06049200   0.015423059463501  
2.38%
-
Stop  1034942601.06084500   0.00035297870635986
0.05%
-
total - 0.64773404598236 
100.00%
-


[yohgaki@dev DEV]$ 




[2002-10-18 06:50:52] [EMAIL PROTECTED]

Damn Mozilla wont work with buffer normally :(
Lets try again.
Problem: read from a text file into array
1. using fread()+explode()
2. using file()

Here my tests

 setMarker('Start');
$fp = fopen("access.log", "r");
$s  = explode("\n", fread($fp, filesize("access.log") ) ) ;
fclose($fp);
$time -> setMarker('fread+explode'); 
$s = file("access.log");
$time -> setMarker('file'); 
$time -> setMarker('Stop');
$time -> display(); 
?

#19971 [Com]: file() function extremally slow

2002-10-18 Thread sazonenkov
 ID:   19971
 Comment by:   [EMAIL PROTECTED]
 Reported By:  [EMAIL PROTECTED]
 Status:   Open
 Bug Type: *Directory/Filesystem functions
 Operating System: win_xp
 PHP Version:  4.2.3
 New Comment:

 setMarker('Start');
$fp = fopen("access.log", "r");
$s  = explode("\n", fread($fp, filesize("access.log") ) ) ;
fclose($fp);
$time -> setMarker('fread'); 
$s = file("access.log");
$time -> setMarker('file'); 
$time -> setMarker('Stop');
$time -> display(); 
?>

access.log 16Mb
fread + explode faster when file(). Hmmm...

 time indexex time% Start1034933111.79707300-0.00%
fread1034933112.398477000.60140417.87%
file1034933115.162048002.76357182.12%
Stop1034933115.162183000.0001350.00% total-3.365110100.00%


Previous Comments:


[2002-10-18 04:11:52] [EMAIL PROTECTED]

It slow even with text files
Sorry for Photoshop.exe-example
I test it even with apache/logs/access.log



[2002-10-18 03:53:15] [EMAIL PROTECTED]

file() is not binary safe; you should not use it on binary files.
When testing the snapshot, try the new file_get_contents() function
too, which is 100% binary safe.
$s = file_get_contents();



[2002-10-18 03:05:02] [EMAIL PROTECTED]

Please try using this CVS snapshot:

  http://snaps.php.net/php4-latest.tar.gz
 
For Windows:
 
  http://snaps.php.net/win32/php4-win32-latest.zip

Ops, wrong quick fix.



[2002-10-18 03:04:43] [EMAIL PROTECTED]

Thank you for taking the time to report a problem with PHP.
Unfortunately you are not using a current version of PHP -- 
the problem might already be fixed. Please download a new
PHP version from http://www.php.net/downloads.php

If you are able to reproduce the bug with one of the latest
versions of PHP, please change the PHP version on this bug report
to the version you tested and change the status back to "Open".
Again, thank you for your continued support of PHP.





[2002-10-18 02:48:08] [EMAIL PROTECTED]

This function is extrimally slow read a file.
On php4.0.4pl1 it much faster (about 100-1000x)!!!
:(

 setMarker('Start');
$fp = fopen("Photoshop.exe", "r");
//$s  = explode("\n", fread($fp, filesize("Photoshop.exe") ) ) ;
fclose($fp);
//print_r($s);
$time -> setMarker('fread'); 
$s = file("Photoshop.exe");
$time -> setMarker('file'); 
$time -> setMarker('Stop');
$time -> display(); 
?>




-- 
Edit this bug report at http://bugs.php.net/?id=19971&edit=1