Getting Internal Server Error while reading on big Excel files

May 21, 2009 at 1:02 PM

Hi

I am getting a strange problem, with a sinple read operation when file size reaches 700 rows I get an internal server error.

 

Any Idea why.

 

Thanks

Developer
May 21, 2009 at 2:36 PM

I have seen this kind happening on shared web hosting solutions when memory limit is exhausted. I am not talking about the usual memory limit governed by PHP. They have various other ways of restricting memory usage. Normally they don't advertise with this kind. Some web hosts will give you just 10-24MB, other give you 40-50MB, if you have 90-100 MB then you're lucky.

1. Find out the effective memory limit. You cannot just look up memory_limit using phpinfo() because you cannot count on that value.

<?php
error_reporting(E_ALL);
ini_set('display_errors', '1');
ini_set('memory_limit', '128M');

$bytes = 5000000;
$x = str_repeat('a', $bytes);
echo " Peak memory usage: " . (number_format(memory_get_peak_usage(true))) . " B\r\n";
?>

Try to raise $bytes until you get some kind of error. Note that although we are using ini_set('memory_limit', '128M'); this may not help any thing on your web hosting, this is what we are testing.

2. There are various ways you can reduce memory usage. We can discuss this once we have some results from 1).

May 21, 2009 at 4:19 PM

Thank you koyama,

I  ran the test and this is result 

Peak memory usage: 5,505,024 B

I am with godaddy, I need a very basic read operation, nothing fancy, can you help how to reduce memory usage.

Please let me know if any older version can help.

 

Thanks


May 21, 2009 at 7:18 PM

It seems that I dont have memory issue, I can use upto 128M. but still getting internal server error.

Any help?

Developer
May 21, 2009 at 8:27 PM

With the largest Excel file you can successfully read, how much memory is the script requiring? Try to put this at the top and bottom of your script and post back the result:

<?php
error_reporting(E_ALL);
ini_set('display_errors', '1');
ini_set('memory_limit', '128M');

/** here should be the code that for reading the Excel file */

echo " Peak memory usage: " . (number_format(memory_get_peak_usage(true))) . " B\r\n";
?>