PHP Excel内存限制2GB耗尽阅读286KB文件 [英] PHP Excel Memory Limit of 2GB Exhausted reading a 286KB file

查看:124
本文介绍了PHP Excel内存限制2GB耗尽阅读286KB文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

附加信息:
我从命令行运行这个。 CentOS 6,32GB RAM总共,2GB内存为PHP。
我尝试将内存限制增加到4GB,但现在我得到一个致命错误:字符串大小溢出 PHP最大字符串大小为2GB

我的代码非常简单的测试代码:

My code is very simple test code:

$Reader = new SpreadsheetReader($_path_to_files . 'ABC.xls');
$i = 0;
foreach ($Reader as $Row)
{   $i++;
    print_r($Row);
if($i>10) break;

}

只能打印10行。那是需要2吉字节的内存?

And it is only to print 10 rows. And that is taking 2 Gigabytes of memory?

错误发生在excel_reader2.php中的第253行

The error is occuring at line 253 in excel_reader2.php

内部课程 OLERead ,里面函数read($ sFilenName)

这是导致我疲惫的代码:

Here is the code causing my exhaustion:

if ($this->numExtensionBlocks != 0) {

        $bbdBlocks = (BIG_BLOCK_SIZE - BIG_BLOCK_DEPOT_BLOCKS_POS)/4;

    }



    for ($i = 0; $i < $bbdBlocks; $i++) { // LINE 253

        $bigBlockDepotBlocks[$i] = GetInt4d($this->data, $pos);

        $pos += 4;

    }


推荐答案

问题。原来与php代码有些无关。

I solved the problem. It turned out to be somewhat unrelated to the php code.

我正在下载的程序下载 .xls .xlsx .csv 从电子邮件和FTP文件。导致内存溢出的 .xls 文件以ASCII模式而不是Binary下载。

The program I am writing downloads .xls, .xlsx, and .csv files from email and FTP. The .xls file that was causing the memory overflow was downloaded in ASCII mode instead of Binary.

我更改了默认为二进制模式,并添加一个支票,将其更改为ASCII模式, .csv 文件。

I changed my default to binary mode, and added a check that changes it to ASCII mode for .csv files.

我还是发现奇怪的是程序创建了一个2GB的字符串,因为这样。如果二进制文件中没有换行符,那么我可以看到整个文件可能会以一个字符串结尾。但文件只有286KB。所以,这很奇怪。

I still find it strange that the program creates a 2GB string because of that. If there are no line breaks in the binary file, then I can see perhaps how the entire file might end up in one string. But the file is only 286KB. So, that's strange.

这篇关于PHP Excel内存限制2GB耗尽阅读286KB文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆