PHPExcel version: 1.7.6
Without special settings, phpExcel will save the read cell information in memory , we can set different caching methods through PHPExcel_Settings::setCacheStorageMethod()
, which has achieved the purpose of reducing memory consumption!
Recommended video tutorials: php introductory tutorial
Solution:
1. Serialize the cell data and save it in memory Medium
PHPExcel_CachedObjectStorageFactory::cache_in_memory_serialized;
2. Serialize the cells and then Gzip compress them, then save them in memory
PHPExcel_CachedObjectStorageFactory::cache_in_memory_gzip;
3. Cache them temporarily disk file, the speed may be slower
PHPExcel_CachedObjectStorageFactory::cache_to_discISAM;
4. Save in php://temp
PHPExcel_CachedObjectStorageFactory::cache_to_phpTemp;
5. Save in 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);
Note that it is added in front of new PHPExcel()
, as follows:
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();
Recommended related article tutorials: php tutorial
The above is the detailed content of What are the solutions to memory overflow when importing big data into phpexcel?. For more information, please follow other related articles on the PHP Chinese website!