duanguangsong2380 2015-07-01 10:03
浏览 377

PHPExcel致命错误:允许的内存大小

I use PHPexcel to open a .xlsx file (on ovh mutualized server) and encountered problems that I solved.

I have a new problem when saving the the modified file :

"Fatal error: Allowed memory size of 536870912 bytes exhausted (tried to allocate 49 bytes) in /home/observatvu/www/libraries/phpexcel/library/PHPExcel/Cell.php on line 870"

I read many questions and answers on internet and tried some solutions like :

  • memory_limit in .htaccess => problem on the server, it does'nt work
  • ini_set('memory_limit','512M') => I have the message above... with other ini_set values I have other sizes of memory error but no saving of the file.
  • I can't modify php.ini

I tried to write setPreCalculateFormulas(false) during saving the file but always the same problem.

Please someone could help me to find a working solution ?

Thank you

  • 写回答

3条回答 默认 最新

  • duanjiongzhen2523 2015-07-01 10:24
    关注

    If you tried

    $cacheMethod = PHPExcel_CachedObjectStorageFactory::cache_to_phpTemp;
    $cacheSettings = array( 'memoryCacheSize' => '1024MB');
    PHPExcel_Settings::setCacheStorageMethod($cacheMethod, $cacheSettings); 
    

    Then it wouldn't work.

    You have a limit of 536,870,912 (512MB) for your PHP

    The line

    $cacheSettings = array( 'memoryCacheSize' => '1024MB');
    

    is telling PHPExcel to use 1024MB of PHP memory before switching to using php://temp for caching.... that's what the memory element of the argument name memoryCacheSize means.

    Use a lower value for the memoryCacheSize value than the amount of your PHP memory limit

    $cacheMethod = PHPExcel_CachedObjectStorageFactory::cache_to_phpTemp;
    $cacheSettings = array( 'memoryCacheSize' => '256MB');
    PHPExcel_Settings::setCacheStorageMethod($cacheMethod, $cacheSettings); 
    
    评论

报告相同问题?

悬赏问题

  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!
  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?