1
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

Mark Baker
  • 199,760
  • 28
  • 325
  • 373
Prakash Raman
  • 11,331
  • 26
  • 71
  • 124
  • possible duplicate of [Allowed memory size of 33554432 bytes exhausted (tried to allocate 43148176 bytes) in php](http://stackoverflow.com/questions/415801/allowed-memory-size-of-33554432-bytes-exhausted-tried-to-allocate-43148176-byte) – PeeHaa Jun 18 '12 at 10:37
  • Read the legendary John Skeet's answer in here http://stackoverflow.com/questions/3674197/fatal-error-allowed-memory-size-of-134217728-bytes-exhausted-tried-to-allocate?rq=1 – Andrius Naruševičius Jun 18 '12 at 10:37
  • Possible differences: different PHP modules installed using more memory, version of PHP, 32-bit or 64-bit PHP (average memory requirement is about 60% more on 64-bit that 32-bit) – Mark Baker Jun 18 '12 at 10:45
  • I tried raising the limit, setting it to "-1". But still does not work. The file being read has only about 10 rows in it. – Prakash Raman Jun 18 '12 at 13:14

2 Answers2

1

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;

Lakin Mohapatra
  • 918
  • 9
  • 18
0

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.

Vil
  • 1
  • 3