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

From: Date: Fri, 18 Oct 2002 11:13:19 +0000
Subject: #19971 [Opn]: file() function extremally slow
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-22758@lists.php.net to get a copy of this message
ID: 19971 Updated by: yohgaki@php.net Reported By: sazonenkov@yandex.ru Status: Open Bug Type: *Directory/Filesystem functions -Operating System: win_xp +Operating System: any -PHP Version: 4.2.3 +PHP Version: 4.3.0-dev New Comment: Please paste readable output... ================================ [yohgaki@dev DEV]$ cat t.php <?php $filename = '/var/log/httpd/error_log.1'; require("Benchmark/Timer.php"); $time = new Benchmark_Timer; $time -> setMarker('Start'); $fp = fopen($filename,'r'); for ($i = 0; $i<100; $i++) $s = fread($fp, filesize($filename)); fclose($fp); $time -> setMarker('fread'); for ($i = 0; $i<100; $i++) $s = file($filename); $time -> setMarker('file'); $time -> setMarker('Stop'); $time -> display(); ?> [yohgaki@dev DEV]$ ./sapi/cli/php t.php ------------------------------------------------------------- marker time index ex time perct ------------------------------------------------------------- Start 1034939438.53591700 - 0.00% ------------------------------------------------------------- fread 1034939438.55064400 0.014726996421814 2.74% ------------------------------------------------------------- file 1034939439.07360900 0.52296495437622 97.21% ------------------------------------------------------------- Stop 1034939439.07387800 0.00026905536651611 0.05% ------------------------------------------------------------- total - 0.53796100616455 100.00% ------------------------------------------------------------- [yohgaki@dev DEV]$ Previous Comments: ------------------------------------------------------------------------ [2002-10-18 04:31:16] sazonenkov@yandex.ru <?php require("Benchmark/Timer.php"); $time = new Benchmark_Timer; $time -> 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% ------------------------------------------------------------------------ [2002-10-18 04:11:52] sazonenkov@yandex.ru 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] wez@php.net 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] mfischer@php.net 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] mfischer@php.net 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. ------------------------------------------------------------------------ The remainder of the comments for this report are too long. To view the rest of the comments, please view the bug report online at http://bugs.php.net/19971 -- Edit this bug report at http://bugs.php.net/?id=19971&edit=1

« previous php.bugs (#22758) next »