2016-12-24 186 views
-1

我正在尝试使用PHPExcel库来读取大型Excel文件。即使我包括这些:阅读大型Excel文件时出现“允许的内存大小已耗尽”错误

ini_set('memory_limit', '1024M'); 
ini_set('max_execution_time', '300'); 

但我仍然收到此错误:

Fatal error: Allowed memory size of 1073741824 bytes exhausted (tried to allocate 234881024 bytes) in D:\xampp\htdocs\BidCrawler\application\third_party\PHPExcel\CachedObjectStorage\Memory.php on line 55

任何想法?

+0

您可以附上调试跟踪结果吗?我猜测这个问题是不够的。 –

回答

0

好像你想读一个大的excel文件。

错误状态,PHP需要234881024字节更多比你分配(1024M),其中翻译为224M。

memory_limit增加为'2048M'之类的东西,看它是否有效。出于测试目的,你可能想分配无限的内存到PHP:

ini_set('memory_limit', '-1') 

顺便说一句,这是很多分配给PHP。尝试以块的形式读取文件,而不是一次读取整个文件。

我的建议是看看nuovo/spreadsheet-reader包,它专门设计用来读取大文件。引用来自文档:

spreadsheet-reader is a PHP spreadsheet reader that differs from others in that the main goal for it was efficient data extraction that could handle large (as in really large) files. So far it may not definitely be CPU, time or I/O-efficient but at least it won't run out of memory (except maybe for XLS files).

据我所知,你使用的是CodeIgniter。为了整合这个包笨,你需要enable composer support

Additionally, if you want CodeIgniter to use a Composer auto-loader, just set $config['composer_autoload'] to TRUE or a custom path in your application's application/config/config.php file.

之后,您可以访问SpreadsheetReader类。请参阅documentation以了解如何充分利用它来读取大型excel文件。

0

尽管你可以放大你的配置的限制,但是对于多用户的php webservice更好。

使用批量读取文件,每次读取一个零件然后处理它。

相关问题