PHP - Server error 500 while processing (not uploading) big file

947 views Asked by At

I try to get an 440mb CSV file into array:

$handle = fopen("stuff.csv", "r");
$data = array();
while (($line = fgetcsv($handle, 1000, ';')) !== FALSE)
{
    $data[] = $line;
}

it breaks up after about 20 seconds, in the PHP ini the max_execution_time is set to 50 and memory_limit to 1024. What could be the trouble?

1

There are 1 answers

1
Alexander Bezpyatov On BEST ANSWER
  1. Did you specified 1024M or just 1024?
  2. It is more possible that 1024Mb is not enough.

You can:

  • check out logs, for that look at error_log value in php.ini
  • increase memory twice and measure time of execution - if it will increase too, it is 100% memory_limit issue

In the future, it is more efficient to process large files in background scripts. You can use Gearman for that.