Prashant
Prashant

Reputation: 2065

PHP Excel 504 nginx timeout at 400 records. Not able to export the excel file

I am trying to export an excel file using PHP excel library. I can export about 400 records. However when I go for more about 600 records, I see nginx timeout error. I have been trying to resolve this issue. Does anyone know how to resolve this?

So far I have played with php options like.. set_time_limit(0); and ini_set('memory_limit','-1');

But still not able to resolve it.

Please help. Thanks in advance.

Thanks for the replies. I contacted my server company and they said they had added fastcgi_read_timeout 360; to nginx setting. and it works now.

However, the download initiates very slowly. I guess its because of the PHP Excel Library. Can anyone suggest how I can get it to respond faster?

Upvotes: 2

Views: 5633

Answers (2)

Mark Baker
Mark Baker

Reputation: 212522

Just a few quick observations from looking at your code:

$objPHPExcel->getActiveSheet()->insertNewRowBefore($row,1);

is an expensive operation (and grows more expensive as the volume of data in your worksheet grows) that you're repeating for every iteration of your foreach() loop. Count how many rows you need, then insert that many new rows before looping.

For every cell you're writing, you're using:

$objPHPExcel->getActiveSheet()->...

this entails a call to the workbook's getActiveSheet() method for every cell. Execute this once before the loop, storing the returned worksheet in a variable (e.g. $ws), then call

$ws->setCellValue()

to set your cell values.

or use the fluent interface:

$objPHPExcel->getActiveSheet()->setCellValue('A'.$row, $first_line)
    ->setCellValue('B'.$row, ucwords($dataRow['intlcode']))
    ->setCellValue('C'.$row, ucwords($dataRow['mobile_number']))
    ->setCellValue('D'.$row, ucwords($dataRow['r_datetime']))
    ->setCellValue('E'.$row, $dataRow['fname'])
    ->setCellValue('F'.$row, $dataRow['lname'])
    ->setCellValue('G'.$row, $dataRow['email'])
    ->setCellValue('H'.$row, $dataRow['picture'])
    ->setCellValue('I'.$row, $dataRow['lang'])
    ->setCellValue('J'.$row, $dataRow['interests'])
    ->setCellValue('K'.$row, $dataRow['title'])
    ->setCellValue('L'.$row, $dataRow['company'])
    ->setCellValue('M'.$row, $dataRow['address'])
    ->setCellValue('N'.$row, $dataRow['app_status']);

Even better if you can use the fromArray() method to set all the cells in the row in a single call.

$objPHPExcel->getActiveSheet()->fromArray($dataRow,NULL,'B'.$row);

Upvotes: 2

b1_
b1_

Reputation: 2126

Nginx error, so change nginx config

proxy_read_timeout

Upvotes: 2

Related Questions