今天在使用PHPExcel撰寫匯出EXCEL表格的功能時,之前一向用的好好的,但這次卻莫名其妙停住了。

看了一下Apache error log 顯示PHP Fatal error:  Allowed memory size of 67108864 bytes exhausted 

暫時將記憶體使用限制調整為 1024M也不行

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

 

http://phpexcel.codeplex.com/workitem/ 搜尋了一下,找到這篇文章 Memory leak 。

其中有提到要設定cache可以減少memory 使用量,正確來說應該是強化garbage機制,節錄code如下:


cacheMethod = PHPExcel_CachedObjectStorageFactory:: cache_to_phpTemp;
cacheSettings = array( ' memoryCacheSize ' => '8MB');
PHPExcel_Settings::setCacheStorageMethod(cacheMethod, cacheSettings);
objPHPExcel = new PHPExcel();

重點是要在create object前就先修改PHPEXcel_Settings的設定值。

文章標籤
全站熱搜
創作者介紹
創作者 jeffath 的頭像
jeffath

jeffath的部落格

jeffath 發表在 痞客邦 留言(1) 人氣(2,833)