phpExcel導入大數據量情況下內存溢出解決方案


PHPExcel版本:1.7.6+

在不進行特殊設置的情況下,phpExcel將讀取的單元格信息保存在內存中,我們可以通過 PHPExcel_Settings::setCacheStorageMethod() 來設置不同的緩存方式,已達到降低內存消耗的目的!

1、將單元格數據序列化后保存在內存中

PHPExcel_CachedObjectStorageFactory::cache_in_memory_serialized; 

2、將單元格序列化后再進行Gzip壓縮,然后保存在內存中

PHPExcel_CachedObjectStorageFactory::cache_in_memory_gzip

3、緩存在臨時的磁盤文件中,速度可能會慢一些

PHPExcel_CachedObjectStorageFactory::cache_to_discISAM;

4、保存在php://temp

PHPExcel_CachedObjectStorageFactory::cache_to_phpTemp; 

5、保存在memcache

PHPExcel_CachedObjectStorageFactory::cache_to_memcache;

$cacheMethod = PHPExcel_CachedObjectStorageFactory::cache_to_memcache; $cacheSettings = array( 'memcacheServer'  => 'localhost',  
     'memcachePort'    => 11211,  
     'cacheTime'       => 600 ); PHPExcel_Settings::setCacheStorageMethod($cacheMethod, $cacheSettings);

注意是加在new PHPExcel() 前面:如下

require_once APPPATH .'third_party/PHPExcel/PHPExcel.php'; $cacheMethod = PHPExcel_CachedObjectStorageFactory::cache_to_phpTemp; $cacheSettings = array('memoryCacheSize'=>'16MB'); PHPExcel_Settings::setCacheStorageMethod($cacheMethod, $cacheSettings); $objPHPExcel = new PHPExcel();

本文源自:https://www.cnblogs.com/myx/archive/2013/05/20/phpExcel-setCache.html ,謝謝博友的講解!


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM