Package home | Report new bug | New search | Development Roadmap Status: Open | Feedback | All | Closed Since Version 1.4.1

Bug #10721 [PATCH] discoverFormat() can't handle large files
Submitted: 2007-04-14 04:33 UTC
From: ieure Assigned: dufuz
Status: Closed Package: File (version 1.2.2)
PHP Version: 5.2.1 OS: Debian 3.1
Roadmaps: 1.3.0a1    
Subscription  


 [2007-04-14 04:33 UTC] ieure (Ian Eure)
Description: ------------ I tried to use discoverFormat() on a 44mb CSV file. It ran PHP out of memory, because it loads the whole file into memory with file(), then grabs the first ten records. Using file() is easier, but clearly not workable when the file size is larger than memory_limit. I've supplied a patch which uses fgets() instead; it works for me. Test script: --------------- require_once 'File/CSV.php'; $fmt = File_CSV::discoverFormat('huge-file.csv'); Expected result: ---------------- discoverFormat() should not kill PHP. Actual result: -------------- discoverFormat() kills PHP with an out of memory error.

Comments

 [2007-04-16 12:24 UTC] dufuz (Helgi Þormar)
You are right, I never really tried this on very large documents, I usually tend to go the way of knowing the format if I was going over couple of megs, I advice against using discoverFormat for really big files but I'll commit this patch later this week if it doesn't add any regression in my test suite Thanks
 [2007-04-17 21:42 UTC] dufuz (Helgi Þormar)
This bug has been fixed in CVS. If this was a documentation problem, the fix will appear on pear.php.net by the end of next Sunday (CET). If this was a problem with the pear.php.net website, the change should be live shortly. Otherwise, the fix will appear in the package's next release. Thank you for the report and for helping us make PEAR better. I reworked the patch a little to match the curren head, thanks for the patch ;)