Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/249.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
php报告速度非常慢,并且在firefox中崩溃_Php_Firefox_Crash - Fatal编程技术网

php报告速度非常慢,并且在firefox中崩溃

php报告速度非常慢,并且在firefox中崩溃,php,firefox,crash,Php,Firefox,Crash,我有一个运行并返回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($

我有一个运行并返回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查询。。。。使用联接执行单个查询将显著提高性能


打印成PDF几乎肯定会慢一些:您需要大量代码来自己在报告中正确定位所有内容,或者使用其中一个可以获取HTML并将其呈现为PDF的库,因为您目前已经在生成HTML了,这将是额外的处理

对啊哈,不是波段。我会试试看。好吧,我实际上完全执行了文档查询,所以只在一个查询上循环结果,它仍然崩溃o使用联接,它将返回多行,因为数据库中每个项目可以有多个文档。使用联接,您可以执行简单的if测试,以匹配第一个表列(如PK)的值,并根据需要对代码进行分支。它需要更多的PHP逻辑,但将执行的数据库查询数从367减少到1。。。这保证了您的性能节约。为什么它会在FF中崩溃是另一回事。是的,谢谢。它在铬合金中工作完美。我想FF目前不是运行报告的最佳选择。无论如何,我们现在不需要那个额外的查询。但我明白你在说什么。