简体   繁体   中英

PHPExcel: Trouble loading large file

I wrote a PHP script that relies heavily on PHPExcel that reads a large file, usually from Dropbox, to add a store's inventory to an the store's ERP website.

This script acts sporadically, sometimes it works and reads the whole thing and other times I get an error saying the maximum allowed memory on the same file. At first I thought this happened because the file was in Dropbox and somehow there was a faulty connection causing it to stop reading midway but I copied the file locally and the same thing happens.

I don't know why this happens and it's driving me insane. I was thinking about having the file be read by a python script instead since I've had better luck reading a large Excel file using openpyxl.

I have a question regarding this route.

I was planning to call the python script using php's exec function

exec("python tesscript.py <fileName>");

The thing about this PHP script is that the file will be sent to it via a form with a file selector on the previous script. Is it possible to pass the file using the exec function?

If you need any further information please let me know and I will gladly provide it.

Thanks!

Since you've mentioned that the file is "large", it may be memory / execution time problem.

Please try adding the following 2 lines at the top of your PHP script (to allocate memory and allow longer execution time):

ini_set('memory_limit', -1); 
ini_set('max_execution_time', 7200);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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