Memory exhausted writing file

Topics: Developer Forum, User Forum
Mar 26, 2013 at 3:04 AM
I have a simple program that generates a file with 11 columns and more than 1100 rows (so more than 121,000 cells). A simple formatting (bottom border) and that's it. But I have a memory exhausted on my host. On my workstation I can raise memory limit but not at my host.

How can I solve my problem? Can I write the file "on-the-fly"? Can I write the file while adding rows?
Mar 27, 2013 at 9:46 AM
For the last two questions, the answer is no.
You can solve the problem by using one of the cache methods offered by PHPExcel, see section 4.2.1 of the documentation, a search in the discussions will give you many examples.
Mar 27, 2013 at 12:51 PM
Nope, nothing happened... :(

I have tried several different cache methods. All gave me the same result:

cache_in_memory (default): 67108864 bytes PHPExcel/Style/Supervisor.php on line 123
cache_in_memory_gzip: 67108864 bytes PHPExcel/Style/Supervisor.php on line 123
cache_to_discISAM (@/tmp): 67108864 bytes PHPExcel/Style/Supervisor.php on line 123
cache_to_sqlite: 67108864 bytes PHPExcel/Style/Supervisor.php on line 123

As you can see, I've got the same amount of memory exhausted with four different cache methods. I was expecting, at least, different memory amounts or different break points...

As far as I understood, all I need to do is write down the cache method I want at the head of my program, am I right?


It seems right. I used var_dump with the line above and PHP returned: string(6) "SQLite". So, it seems PHPExcel applied this cache method, but I still get the error.

My program is writing the output to php://output but it doesn't matter right now because the program stops before reaching the output...

So, what now?

Mar 27, 2013 at 5:28 PM
Edited Mar 28, 2013 at 7:57 AM
You need to call setCacheStorageMethod :

$cacheMethod = PHPExcel_CachedObjectStorageFactory::cache_in_memory;

Additionally, you can test the return value of the method (a boolean, true=>Ok, false=>can't use).

Edit : Replace cache_in_memory with the desired cache. You can have a second parameter (an array) for additional settings like a directory to use, a port to connect, etc. See the documentation for more infos. Check if you have the related extension enabled.