我开发了一个带PHP的软件并使用TCPDF进行报告。它运行良好,但在MySQL中导入大量数据后,PHP无法在浏览器超时之前生成报告。我尝试过最新的firefox和Chrome版本。
这是我的剧本:
<?php
require_once('tcpdf/config/lang/eng.php');
require_once('tcpdf/tcpdf.php');
// create new PDF documentation
include "koneksi.php"; //file conection
$bln=$_POST[BLN]; //for catch month
$thn=$_POST[THN]; //for catch year
$exp=$_POST[EXP]; //for catch expedition name
if(empty($exp))
{
$sql = "SELECT * FROM tb_exp_local where bulan = '$bln' AND tahun = '$thn'";
}
elseif($exp != "")
{
$sql = "SELECT * FROM tb_exp_local where bulan = '$bln' AND tahun = '$thn' AND nama_exp = '$exp'";
}
$hasil = mysql_query($sql);
$pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
// set font
$pdf->SetFont('times', '', 11);
// landscape
$pdf->addPage( 'L', 'LETTER' );
//this for convert html to pdf with html function
$html = '
<table border="1" cellspacing="3" cellpadding="4">
<tr><td colspan="9" align="center"><h2>Form Pantauan Expedisi Export</h2></td></tr>
<tr>
<th align="center"><b>Tanggal</b></th>
<th align="center"><b>Nama Expedisi</b></th>
<th align="center"><b>Nama Distributor</b></th>
<th align="center"><b>Kota Tujuan</b></th>
<th align="center"><b>No Faktur</b></th>
<th align="center"><b>Kondisi Armada Pengiriman</b></th>
<th align="center"><b>Ketepatan Jumlah</b></th>
<th align="center"><b>Ketepatan Waktu Kirim</b></th>
<th align="center"><b>Keterangan</b></th>
</tr></table>';
while ($data = mysql_fetch_array($hasil))
{
$html .= '<table border="1"><tr><td align="center">'.$data['tgl'].'</td>
<td align="center">'.$data['nama_exp'].'</td>
<td align="center">'.$data['nama_dist'].'</td>
<td align="center">'.$data['kota_tujuan'].'</td>
<td align="center">'.$data['faktur'].'</td>
<td align="center">'.$data['konarmada'].'</td>
<td align="center">'.$data['tepatjml'].'</td>
<td align="center">'.$data['tepatwaktu'].'</td>
<td align="center">'.$data['ket'].'</td>
</tr></table> ';
}
$pdf->writeHTML($html, true, false, true, false, ''); //for generate
$pdf->Output('FormPantauExpLocalAll', 'I'); // for generate pdf file
?>
答案 0 :(得分:1)
服务器超时不依赖于浏览器。尝试在循环中使用set_time_limit(60):
while ($data = mysql_fetch_array($hasil))
{
set_time_limit(60);
$html .= '(...)';
}
另外,尝试将INDEX添加到(bulan,tahun,nama_exp)列上的数据库中,它应该加快检索过程。另外,请注意在此过程中可能会耗尽内存(检查服务器上的PHP日志)