What are the solutions to memory overflow when importing big data into phpexcel?

王林
Release: 2023-04-07 21:12:01
Original
4348 people have browsed it

What are the solutions to memory overflow when importing big data into phpexcel?

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;
Copy after login

2. Serialize the cells and then Gzip compress them, then save them in memory

PHPExcel_CachedObjectStorageFactory::cache_in_memory_gzip;
Copy after login

3. Cache them temporarily disk file, the speed may be slower

PHPExcel_CachedObjectStorageFactory::cache_to_discISAM;
Copy after login

4. Save in php://temp

PHPExcel_CachedObjectStorageFactory::cache_to_phpTemp;
Copy after login

5. Save in memcache

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

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();
Copy after login

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!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template