简体   繁体   English

如何使用phpexcel阅读器读取非常大的csv文件

[英]how to read very large csv files using phpexcel reader

I am trying to read a csv file of size 980mb using phpexcel reader, but my code is reading smaller files(upto 4mb), but how to read larger csv or excel files using phpexcel reader??[i am a fresher in php and phpexcel function too].Please help me it this possible? 我正在尝试使用phpexcel阅读器读取大小为980mb的csv文件,但是我的代码正在读取较小的文件(最大4mb),但是如何使用phpexcel阅读器读取较大的csv或excel文件?[我在php和phpexcel中比较新鲜功能也一样。)请帮我这可能吗? Thanks in advance. 提前致谢。

If you don't care about how long it takes and how much memory it needs, you can simply increase the values for this script. 如果您不需要花费多长时间和需要多少内存,则可以简单地增加此脚本的值。 Just add the following lines to the top of your script: 只需在脚本顶部添加以下几行:

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

With the function memory_get_usage() you can find out how much memory your script needs to find a good value for the memory_limit. 使用memory_get_usage()函数,可以找出脚本需要多少内存才能为memory_limit找到合适的值。

You might also want to have a look at fgets() which allows you to read a file line by line. 您可能还想看看fgets() ,它使您可以逐行读取文件。 I am not sure if that takes less memory, but I really think this will work. 我不确定这是否需要较少的内存,但是我真的认为这会起作用。 But even in this case you have to increase the max_execution_time to a higher value. 但是即使在这种情况下,您也必须将max_execution_time增加到更高的值。 you can increase excution time as per requirment. 您可以根据要求增加执行时间。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM