1

I am getting below error while reading large .xls file say 29MB (3 sheets, 28000 rows/sheet) using Spreadsheet_Excel_Reader.

Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 71 bytes) in...

I changed memory_limit in php.ini to 128M, and also tried change it run time as ini_set('memory_limit', '-1'); for unlimited but error not solved.

hardik
  • 43
  • 1
  • 9

3 Answers3

0

Not sure you could do '-1'.

You could try :

ini_set('memory_limit', '512M');
Loïc
  • 11,804
  • 1
  • 31
  • 49
  • '-1' works great for my other small amount of file size. I also tried other options to change memory limit with 32M, 64M, 128M, 256M and 512M but issue not solved. – hardik Mar 04 '14 at 04:25
0

ini_set('memory_limit', '-1'); overrides the default PHP memory limit

AND/OR

ini_set('max_execution_time', INCREASE TIME);
Pratik
  • 810
  • 6
  • 26
  • yes, I know ini_set('memory_limit', '-1'); overrides the default PHP memory limit, but the problem is still I'm getting fatal error for memory limit. – hardik Mar 04 '14 at 04:28
  • please check it in your php.ini file how much you have given it? – Pratik Mar 04 '14 at 04:32
  • in php.ini I have set 256M – hardik Mar 04 '14 at 04:35
  • have you tried with ini_set('memory_limit', '-1'); ? If yes,then probably the (while,for,...) loop is running infinitely OR debug with memory_get_usage function – Pratik Mar 04 '14 at 04:39
  • `$data = new Spreadsheet_Excel_Reader(); echo memory_get_usage() . "\n"; // retunrs 5820096 $data->read("[my-filepath]"); // Fatal error occurs here echo memory_get_usage() . "\n";` This how my code looks and debug results commented there. – hardik Mar 04 '14 at 04:48
  • please refer http://stackoverflow.com/questions/11081058/php-excel-reader-allowed-memory-size-of-134217728-bytes-exhausted – Pratik Mar 04 '14 at 04:54
0

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
  • 1,097
  • 11
  • 22