gpt4 book ai didi

php - PHP的报告是非常缓慢的,并在Firefox崩溃

转载 作者:行者123 更新时间:2023-12-03 17:41:17 25 4
gpt4 key购买 nike

我有一个运行并返回366条记录的报告,每个记录包含104 x 80 px的缩略图。问题是,即使我增加了内存大小,报表也运行得非常缓慢。

ini_set('memory_limit', '128M');
ini_set('max_execution_time','600');

编写SQL查询后,我在这里生成表项
generate_table_items($query_all_items);

然后,这将贯穿并检查列中的图像
function generate_table_items($query){
$columns = array();
$resultset = array();

$scriptname = array();
$scriptname[0] = "/reports/all_items.php";
$scriptname[1] = "/reports/all_items_by_value.php";
$columncount = 0;

$rowcost = 0;
$rowsale = 0;

while ($row = mssql_fetch_assoc($query)) {

if (empty($columns)) {

$columns = array_keys($row);
echo '<tr><th scope="col" >'.implode('</th><th scope="col" >',get_column_name($columns)).'</th></tr>';
$columncount = sizeof(array_keys($row));
}
$resultset[] = $row;

echo '<tr><td>'.implode('</td><td>',report_image_check($row)).'</td></tr>';

if(in_array($_SERVER['SCRIPT_NAME'],$scriptname)){
$colspan = (count($columns)-2);
echo "<tr><th scope='row'>Documents</th><td colspan='$colspan' >";
$PKID = $row['ID'];

if($row['SumOfTotalCost'] || $row['SumOfSalePrice']){
$rowcost += $row['SumOfTotalCost'];
$rowsale += $row['SumOfSalePrice'];
$get_total = true;
}

$query_docs = mssql_query("select documents.* from dbo.documents where documents.Antiquities_id = $PKID") or die ('get docs query failed ' . mssql_get_last_message());
while($row_docs = mssql_fetch_assoc($query_docs)){
$document = "../documents/" . $row_docs['document'];
echo "<a href='$document' title='opens in a new window' target='_blank' >" . $row_docs['document'] . "</a> | ";
} // End while (list docs)
mssql_free_result($query_docs);
echo "</td></tr>";
myflush();
} // End if all items and all items by value report

} // End While
echo '<tr>';
for($i=0;$i < $columncount-4;$i++){
echo '<td>&nbsp;</td>';
}
echo '<td>Total Cost '. $rowcost.'</td>';
echo '<td>Total Sale '. $rowsale.'</td>';
echo '<td>Total Calculated Difference '. ($rowsale-$rowcost).'</td></tr>';

} // End function

function get_column_name($columns){
$newcol = array();
$scriptname = array();
$scriptname[0] = "/reports/all_items.php";
$scriptname[1] = "/reports/all_items_by_value.php";
$thecount = 0;
foreach($columns as $col) {
if($thecount == 1 && in_array($_SERVER['SCRIPT_NAME'],$scriptname)) {
// Don't list the PK
} else {
$newcol[] = '<img id="'.$col.'" src="../images/icons/arrow_down.png" alt="click to sort by" onclick="sortby(\''.$col.'\');" />' . $col;
}
$thecount++;
}

/*if(in_array($_SERVER['SCRIPT_NAME'],$scriptname)){
$newcol[] = "documents";
}*/

return $newcol;
}

function report_image_check($row){
global $base_url, $uploaded_images_folder;
$newrow = array();
$imageext = array();

$imageext[0] = ".jpg";
$imageext[1] = ".png";
$imageext[2] = ".gif";
$imageext[3] = ".tiff";

$scriptname = array();
$scriptname[0] = "/reports/all_items.php";
$scriptname[1] = "/reports/all_items_by_value.php";
$PKID = 0;
$thecount = 0;

foreach($row as $rn) {

if(in_array(strtolower(substr($rn,-4)),$imageext)){
$small_img_ext = substr($rn,-4);
$small_img = substr($rn,0,strripos($rn,"."));
$small_img = $small_img . '_140_105' . $small_img_ext;
$newrow[] = '<a href="' . $base_url . $uploaded_images_folder . '/' . $small_img . '" title="click to zoom on image" target="_blank" ><img src="' . $base_url . $uploaded_images_folder . '/' . $rn . '" alt="" width="50px" height="50px" /></a>';
} elseif($thecount == 1 && in_array($_SERVER['SCRIPT_NAME'],$scriptname)) {
$PKID = $rn;
} elseif($thecount == 2 && in_array($_SERVER['SCRIPT_NAME'],$scriptname)) {
$newrow[] = "<a href='../index.php?template=10&amp;PKID=$PKID' target='_blank' >$PKID (click to view)</a>";
} else {
$newrow[] = $rn;
}

$thecount++;
myflush();
}

/*if (in_array($_SERVER['SCRIPT_NAME'],$scriptname)) {
$newrow[] = "<a href='#&amp;PKID=$PKID' target='_blank' >Documents (click to view)</a>";
}*/

return $newrow;

} // End function

//// Flushing function
function myflush(){

ob_implicit_flush();
ignore_user_abort();
}

谁能看到此代码的问题,或者为什么要花这么长时间或为什么它会使Firefox崩溃?打印到pdf函数会更好吗?

最佳答案

这将花费很长时间,因为您要嵌套SQL查询...对第一个查询返回的每个结果执行第二个SQL查询...。使用JOIN进行单个查询将显着提高性能。

打印到PDF几乎肯定会比较慢:您需要大量的代码来自己直接在报表中正确放置所有内容,或者使用一种可以将HTML呈现为PDF的库(因为您已经在无论如何目前都会生成HTML,这将是额外的处理)

关于php - PHP的报告是非常缓慢的,并在Firefox崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8803138/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com