zoukankan      html  css  js  c++  java
  • 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 ,谢谢博友的讲解!

  • 相关阅读:
    面向对象
    数据库,连接查询
    主外键,子查询
    字符串函数
    数据库。模糊查询,聚合函数,时间日期函数
    数据库。增,删,改,查
    数据库
    多窗体及菜单
    winform公共控件及其常用属性
    winform 客户端应用程序(c/s b/s)
  • 原文地址:https://www.cnblogs.com/chrdai/p/8581026.html
Copyright © 2011-2022 走看看