2013-04-26 120 views
0

请帮我解决将大数据导出为ex​​cel格式xlsx的问题。 我每次导出几乎45000条记录到单个文件,并且超时而不保存文件。 mysql选择查询需要21秒来执行该大数据。以下是我使用PHP Excel库将数据导出到Excel文件的代码。PHPExcel超时发生

$sql2 = "SELECT * FROM Surveys"; 
$result2 = mysql_query($sql2); 

while($row2 = mysql_fetch_assoc($result2)) 
{ 
$j=$rowscounter+2; 
$sheet->setCellValue("A$j",$row2['brandname']); 
$sheet->setCellValue("B$j",$row2['productname']); 
$sheet->setCellValue("C$j",$row2['sname']); 
$sheet->setCellValue("D$j",$row2['smobile']); 
$sheet->setCellValue("E$j",$row2['semail']); 
$sheet->setCellValue("F$j",$row2['country']); 
$sheet->setCellValue("G$j",$row2['city']); 
$sheet->setCellValue("H$j",$row2['sdob']); 
$sheet->setCellValue("I$j",$row2['age']); 
$sheet->setCellValue("J$j",$row2['comment']); 
$sheet->setCellValue("K$j",$row2['outletcode']); 
$sheet->setCellValue("L$j",$row2['username']); 
$sheet->setCellValue("M$j",$row2['datetime']); 
$sheet->setCellValue("N$j",$row2['duration']); 
$rowscounter++; 
} 

// Rename worksheet 
$sheet->setTitle('Survey-Report');  
$objPHPExcel->setActiveSheetIndex(0); 
$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007'); 
$objWriter->setPreCalculateFormulas(false); 
unlink("Survey-Report.xlsx"); 
$objWriter->save('Survey-Report.xlsx'); 
echo "ok"; 

UPDATE:

我忘了提,我已经尝试过set_timout等,并在我的PHP文件下面的代码中写道。

set_time_limit(0); 
ini_set('memory_limit','2500M'); 
+0

php.ini中有一个变量用于为php脚本执行设置超时值[1]。如果你碰到那可能解决你的问题。 [1]:http://php.net/manual/en/function.set-time-limit.php – 2013-04-26 15:32:55

回答

0

你可以在你的脚本的顶部添加此:

set_time_limit (0); 

这将禁用默认30秒PHP超时。

或者你可以添加自定义秒数,看到set_time_limit()

+0

感谢您的回答。我更新了我的描述。我已经补充说,没有运气。 – Deeps 2013-04-26 15:42:26

+0

好吧,在这种情况下,如果你正在得到一个'timeout',那么它可能是一个Apache超时(或者与其他web服务器相同),请阅读http://www.php.net/manual/en/info.configuration .php#如果ini.max,执行时间 – Nelson 2013-04-26 15:48:07

0

我,我继续使用PHPExcel导出记录时得到一个504网关超时了同样的问题。我也试过set_time_limit(0)没有成功。我最终做的是改变Apache的超时。

你可以在你的httpd.conf文件中找到这个timout

希望它有帮助!

相关问题