PHPExcel版本:1.7.6
#在不進行特殊設定的情況下,phpExcel將讀取的單元格資訊保存在內存中,我們可以透過PHPExcel_Settings::setCacheStorageMethod()
來設定不同的快取方式,已達到降低記憶體消耗的目的!
相關影片教學推薦:php入門教學
解決方案:
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();
以上是phpexcel導入大數據記憶體溢出的解決方法有哪些的詳細內容。更多資訊請關注PHP中文網其他相關文章!