Out of memory

Topics: Developer Forum
Mar 1, 2010 at 7:59 AM

Hi,

I generate an excel and php throw me the error:  "Out of memory (allocated 515637248) (tried to allocate 68 bytes)".  The memory seems pretty big so i suppose the problem is generated by my scripts which generate the excel and i don't figure out what I'm doing wrong.The final excel has 2-300 KB.

I can attach a sample of generated excel but I preffer to keep this file private .

Mar 2, 2010 at 7:10 AM

I have a similar problem - the memory used by PHPExcel is quite big. Is there any chance to have it reduced in the near future?

Coordinator
Mar 2, 2010 at 7:50 AM

There are many threads about the memory usage of PHPExcel here on the board, and most reiterate the same thing.

Yes, we are actively working on reducing the memory usage. We've already made significant inroads, and provided a number of facilities that allow you to read in only certain worksheets or parts of worksheets or the data only (no formatting information) to reduce the volumes of data and corresponding memory usage. The latest SVN code includes a lazy loader that only accesses the PHPExcel classes that you actually need within your script (current 1.7.2 code still includes all classes) in order to reduce the memory footprint.

And we are still working on this.

Mar 5, 2010 at 12:41 PM
MarkBaker wrote:
The latest SVN code includes a lazy loader that only accesses the PHPExcel classes that you actually need within your script (current 1.7.2 code still includes all classes) in order to reduce the memory footprint

Hi,

thx for ur great job on PHPexcel.

i have similar problem too, as ur direction where can i download the latest SVN that include lazy loader, and how to configure it on my PHPexcel 1.7.2

thx for ur reply Mr. Mark Baker

 

Coordinator
Mar 5, 2010 at 8:46 PM

The Daily SVN builds can be found under the "Source" tab here on CodePlex PHPExcel

http://phpexcel.codeplex.com/SourceControl/list/changesets

 

Mar 10, 2010 at 8:30 AM

hi,

thx for ur quick reply, i have downloaded http://phpexcel.codeplex.com/SourceControl/list/changesets , but i still have same error

Fatal error: Allowed memory size of 16777216 bytes exhausted (tried to allocate 67 bytes) in /var/www/Classes/PHPExcel/Worksheet.php on line 939

pls let me know how to solve  this problem?

Coordinator
Mar 10, 2010 at 12:50 PM
Edited Mar 11, 2010 at 12:39 PM
vatoer wrote:

pls let me know how to solve  this problem?

 

At present, the only way to solve this problem is to allocate more memory to PHP by changing the memory_limit setting in php.ini, e.g

memory_limit=32MB

setting an .htaccess entry to increase the allocated memory, e.g

php_value memory_limit 32M

or (may not work) changing the limit at the top of your script, e.g

ini_set(’memory_limit’, ‘32M’);

We are actively working on this. I've spent most of the last two weeks prototyping a mechanism for "cell caching" which can reduce memory usage drastically, but at a cost in performance. Basically, only the currently active cell object is resident in memory at any one time. Other cells might be held serialized in memory, or stored on disk or in a database, or in APC or memcache; but at a cost in speed... whenever another cell is accessed, the first is stored back in cache, and the newly requested cell retrieved from cache.
There is no simple solution: if reducing memory usage results in constant timeouts, then it isn't a viable solution. We're looking for the best solution that will accomodate all users of PHPExcel so that you don't hit memory or timeout problems, and the work I'm doing at the moment is analysing and tuning to find the best memory reduction with the minimum increase in execution time.

As an example (for 16,384 cells):

Cell Storage Method Memory Usage
(MB)
Cell Creation time
(seconds for
16,384 cells)
Cell retrieve time
(seconds for
16,384 cells)

Cell modify time
(seconds for
16,384 cells)

Current cell storage 12.25 0.2293 0.0674 0.2117
Serialized cell storage 9 0.4141 0.3384 1.5574
APC cell storage 0 0.9113 0.5387 2.8961
Memcache cell storage 0 11.6727 5.6859 18.4403
Disk (Partial) cell storage
(using an ISAM file for all cells)
4.75 1.0742 0.7211 2.9781
Disk (Full) cell storage
(using a temporary file for each cell)
0 45.04405 10.4741 66.5842

As you can see, the more we reduce the memory usage, the slower a script will run. APC or Full Disk storage offer the best memory footprint (only the currently accessed cell is ever resident in PHP memory at any time); but not every user has APC enabled, and the speed for Full Disk storage is simply not acceptable. Serialized cell storage and Partial Disk storage seem to offer the best balance of memory reduction and script execution time; but they're still very slow in comparison to the current method of holding every cell object in memory.

We are trying to resolve this problem, and while we have already achieved a great deal in reducing the memory footprint, we know there's still a lot more work to do before we can consider the problem is resolved. Please bear with us while we do that work.

Mar 11, 2010 at 2:44 AM
MarkBaker wrote:

At present, the only way to solve this problem is to allocate more memory to PHP by changing the memory_limit setting in php.ini, e.g

memory_limit=32MB

setting an .htaccess entry to increase the allocated memory, e.g

php_value memory_limit 32M

or (may not work) changing the limit at the top of your script, e.g

ini_set(’memory_limit’, ‘32M’);

..........

thx for temporary solve the problem.

just for information ( i hope this will give u little useful information )

i create excel from template with file size : 7KB

i try to increase my mymory up to 32M and the result can produce maximum +- 444 new inserted row and Y column in my excel template

64M -> +- 900 new inserted row , Y column

128M -> +- 1800 new inserted row , Y column

 

i really appreciated for ur great job n hopefully u can do it with unyielding spirit. thanks for sharing your knowledge

Jan 24, 2013 at 12:01 PM
Edited Jan 25, 2013 at 11:09 AM

I have also similar problem

 use PhpExcel in CodeIgniter.When I generate huge amount of data in Excel it will produce Fatal error:

 Out of memory (allocated 883949568) (tried to allocate 93 bytes) in /home/abc/public_html/xxx/application/libraries/excel/PHPExcel/Style.php on line 465.

Even though I set memory_limit in controller ini_set( "memory_limit","5120M"); and also in php.ini.

I also set cell caching in controller.

I set memoryCacheSize in PHPExcel/CachedObjectStorage/PHPTemp.php 1MB to 5120MB.

I also increase the cacheTime in PHPExcel/CachedObjectStorage/Memcache.php 600 to 259200 and also in othef file in CachedObjectStorage.

but could not solve this problem.

Please let me know how to solve this problem?