如何解决PHPExcel内存不足错误?

I am using PHPExcel to generate Excel reports:

  • I have a report which is around 600kb
  • The report has 15 sheets
  • Each sheets contains approximately 200 rows and 12 columns.
  • One sheet contains formulas.
  • I am using PHPExcel for both reading and writing.
  • I am using amazon free web tier server
  • I am having approximately 600MB RAM in the server

The problem is that the process writing to the excel file is getting killed (due to out of memory)

What should I do? Are there any other Excel libraries available? I want a library with both read and write capabilities.

Is there another way to solve the out of memory problem?

I find it hard to believe that a 600kb file run through PHPExcel would fill up 600MB of memory. It's probably just the memory allocated to PHP that runs out. You can increase the memory available to PHP scripts by using one of these methods:

  • Adding memory_limit = 16M to your php.ini file (recommended, if you have access) With root access, you can use the sed util in Linux/Unix based systems, in order to increase the memory for 64M. Don't forget to properly locate your php.ini file! sed -i 's/memory_limit = .*/memory_limit = 64M/' /etc/php5/apache2/php.ini
  • Adding ini_set('memory_limit', '16M'); to your php script
  • Adding php_value memory_limit 16M to your .htaccess file in the root folder of your project