note 30521 added to function.file-get-contents

From: Date: Thu, 20 Mar 2003 21:46:27 +0000
Subject: note 30521 added to function.file-get-contents
Groups: php.notes 
Request: Send a blank email to php-notes+get-45575@lists.php.net to get a copy of this message
I was recently running some PHP version prior to 4.3.0 and had a small script loading a very large file containing some HTML - I made some regular expression matches on content and it went quite fast..(- I had less than a second execution time). I then upgraded to PHP 4.3.0 and suddenly my script ate my CPU and halted after 30 seconds. It seems since they made the function binary-safe the performance hit rock bottom. My advice: If you have rather large files (something like >1 MB) - I suggest you use fopen() and fread() : $fp = fopen($file,"r"); $content = fread($fp,filesize($file)); ... /* Do something */ fclose($fp); This did the trick for me, my execution time is now back to normal. (Note: I did however test file() on smaller files, though slow, it worked - and I also tested file() on a fresh installation) Specs.: AMD Athlon XP 1800+, 256 MB RAM, Windows 2000 (and XP tried), Apache 1.3, PHP 4.2.3 -- http://www.php.net/manual/en/function.file-get-contents.php http://master.php.net/manage/user-notes.php?action=edit+30521 http://master.php.net/manage/user-notes.php?action=delete+30521 http://master.php.net/manage/user-notes.php?action=reject+30521

« previous php.notes (#45575) next »