简体   繁体   中英

php-excel-reader Allowed memory size of 134217728 bytes exhausted

require_once 'Excel/reader.php';
$data = new Spreadsheet_Excel_Reader();

$data->read('Senator.xls');

I get the following error in my error.log

PHP Fatal error:  Allowed memory size of 134217728 bytes exhausted (tried to allocate 32 bytes)

The weird thing is, this works perfectly fine on my development instance. But not in production. What differences should I be looking for.

note: both envs have memory_limit=128M

Probably one server has a 64 bit processor. The GetInt4d bit shift doesn't work with 64 bit processors.

Use this hack to ensure correct result of the <<24 block on 32 and 64bit systems, just replace the code of the GetInt4d function with the following: Location : Excel/olereader.inc line no-27 ,function GetInt4d()

$_or_24 = ord($data[$pos+3]);

if ($_or_24>=128) $_ord_24 = -abs((256-$_or_24) << 24); else $_ord_24 = ($_or_24&127) << 24;

return ord($data[$pos]) | (ord($data[$pos+1]) << 8) | (ord($data[$pos+2]) << 16) | $_ord_24;

Depends on witch line it's giving the error: mine is

PHP Fatal error:  Allowed memory size of 67108864 bytes exhausted (tried to allocate 32 bytes) in [] on line 1688

it is the function

addcell($row, $col, $string, $info=null) {

in particular the foreach loop. As i understood it's info about color cell offset or something similar so i commented the loop and now it is using much less memory.

If you don't need the execution of such code you can comment it and try.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM