2012-01-10 9 views
0

レポートが実行され、それぞれが104 x 80ピクセルのサムネイルを含む366レコードを返します。問題は、メモリサイズを増やしても、レポートが非常に遅く実行されることです。phpレポートが非常に遅く、Firefoxでクラッシュする

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関数への印刷はうまくいくのでしょうか?

答えて

0

SQLクエリをネストしているので、時間がかかるでしょう...最初のクエリで返されたすべての結果に対して2番目のSQLクエリを実行しています.... JOINを使用して1つのクエリを実行すると、パフォーマンスが大幅に向上します。

PDFへの印刷は、ほとんど確実に遅くなります。レポート内のすべてを正しく配置するためのコードが必要になります。また、HTMLを使用してPDFにレンダリングできるライブラリを使用するとにかく現時点でHTMLを生成していますが、これは追加の処理になります)

+0

右のaha(バンドではありません)。私はそれを試みます。 –

+0

私は実際にドキュメントクエリを完全に取り出しました(したがって、1つのクエリ全体で結果をループするだけです)、それでもクラッシュします。 :o(そして、ジョインでは、データベース内の項目ごとに複数の文書が存在する可能性があるため、複数の行を返します。 –

+0

ジョインでは、単純な「if」テストを実行して、最初のテーブルの列(PKなど)を使用してコードを適切に分岐します。PHPロジックをもう少し必要としますが、実行するデータベースクエリの数を367から1に減らして、パフォーマンスの低下を防ぎます。 –

関連する問題