2015-06-29 51 views
1

我正在使用TCPDF下載PDF。對於較小的記錄,它正在fine.But對於大數據,即1000個記錄,它顯示了以下錯誤,TCPDF內存問題允許的內存大小爲134217728字節耗盡

Fatal error: Maximum execution time of 30 seconds exceeded 
Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 72 bytes) 

我一直在使用的ini_set設置內存限制在PHP最大的執行時間,但它不是works.I也嘗試將php.ini中的memory_limit值從128M更改爲512M。這也不起作用。

我的文件是

<html lang="en"> 
    <head> 
     <meta charset="utf-8"> 
     <meta http-equiv="X-UA-Compatible" content="IE=edge"> 
     <meta name="viewport" content="width=device-width, initial-scale=1"> 
     <meta name="description" content=""> 
     <meta name="author" content=""> 
     <title>Customer Receipts Report</title> 
     <!-- Bootstrap Core CSS --> 

     <style> 
      @font-face { 
      font-family: SourceSansPro; 
    src: url(../../fonts/SourceSansPro-Regular.ttf); 
/* font-family: Roboto; 
    src: url(../fonts/Roboto-Regular.ttf);*/ 
} 
table { 
    width: 100%; 
    border-collapse: collapse; 
    border-spacing: 0; 
    margin-bottom: 20px; 
    font-family:"Armata", sans-serif; 
} 

table th, 
table td { 
    padding: 5px; 
    background: #EEEEEE; 
    text-align: center; 
    border-bottom: 1px solid #FFFFFF; 
} 

table th { 
    white-space: nowrap;   
    font-weight: normal; 
    background: #4A7171; 
    color:white; 
    font-size:12px; 
} 
      html,body{ 
       overflow: hidden; 
      } 
      .login{color:#fff} 
      .table-responsive table td 
      { 
       font-weight: 400; 
       font-size: 12px; 
       color:#222; 
       text-align:center !important; 
      } 
      .form-control { 
       border:1px solid #eee; 
      } 
      .input-sm 
      { 
       border-radius: 3px; 
      } 
      input.input-sm 
      { 
       margin-left: 10px 
      } 
      #dataTables-example_info,#dataTables-example_length label 
      { 
       color:#666; 
      } 
      #dataTables-example_wrapper { 
    width: 86.5% !important; 
} 
      label{ 
       text-transform: lowercase; 
      } 
      .black_overlay{ 
    display: none; 
    position: absolute; 
    top: 0%; 
    left: 0%; 
    width: 100%; 
    height: 100%; 
    background-color: grey; 
    z-index:1001; 
    -moz-opacity: 0.8; 
    opacity:.80; 
    filter: alpha(opacity=80); 
     } 

     .white_content { 
       display: none; 
       position: fixed; 
       top: 7%; 
       left: 20%; 
       padding: 16px; 
       border: 2px solid #7B8D8C; 
       background-color: white; 
       z-index:1002; 
       overflow: auto; 
       height:auto;         
       width: 30cm; 
       height: 35cm; 
       overflow-y: scroll; 
       max-height: 700px; 
     } 
     #wrapper {width:auto ;margin-bottom:5px;} 
     #left{ 
     float:left; 
     width:45%; 
     /*background:#7B8D8C*/ 

     } 
     #right{ 
     /*background:#7B8D8C;*/ 
     float:right; 
     width:45%; 
     height:50%; 
     } 

    </style> 
    </head> 
    <body> 

      <div id="page-wrapper"> 
       <div class="row"> 
        <div class="col-lg-12"> 
         <div class="panel-body"> 
          <table style='width:100%;' border=0> 
<tr> 
<td style='vertical-align:top;text-align:left;background-color:black;'><img src="../../images/logo.png" style="width:140px;margin-left: 20px"/></td> 
<td colspan=2 style='background-color:black;color:white;font-size:9px;'> <div style='text-align:right;'> 
     <div>Company</div> 
     <div>Address</div> 
     <div>Address</div> 
     <div style='color:white !important;'><a href="mailto:[email protected]" style='text-decoration:none;'>[email protected] </a></div> 
     </div> 
</td></tr> 
    </table> 


           <div class="table-responsive"> 
             <br> 

              <h3 class="page-header" style="text-align:center;"><i class="fa fa-road fa-fw" style="padding-right:10px;"></i> Receipts Report </h3> 
           <table class="table table-striped table-bordered table-hover" id="dataTables-example" style='width:100% !important;'> 
            <thead> 
             <tr style="background-color:black;color:white;"> 
              <th><i class="fa fa-user"></i> Customer Name</th> 
              <th><b>#</b> Invoice Number</th> 
              <th><i class="fa fa-calendar"></i> Invoice Date</th> 
              <th ><i class="fa fa-calendar"></i> Due date</th> 

              <th><i class="fa fa-credit-card"></i> Payment Status</th> 
              <th><i class="fa fa-dollar" style="min-width:10px"></i> Amount</th>       

             </tr> 
            </thead> 
            <tbody> 
             <?php 
             $total=0; 
             for($i=0;$i<count($obj['ar_info']);$i++){ 

              echo "<tr><td>".$obj['ar_info'][$i]['customer_name']."</td><td>".$obj['ar_info'][$i]['invoice_number']."</td><td>".$obj['ar_info'][$i]['invoice_date']."</td><td>".$obj['ar_info'][$i]['due_date']."</td><td>".$obj['ar_info'][$i]['payment_status']."</td><td>".$obj['ar_info'][$i]['invoice_amt']."</td></tr>"; 

             } 
             ?> 
            </tbody> 
           </table> 

          </div> 
          <!-- /.table-responsive --> 

         </div> 
         <!-- /.panel-body --> 
        </div> 
        <!-- /.col-lg-12 --> 
       </div> 

      </div> 


     </div> 


    </body> 
</html> 




    $pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false); 

$pdf->SetCreator(PDF_CREATOR); 
//$pdf->SetAuthor('Nicola Asuni'); 
//$pdf->SetTitle('TCPDF Example 049'); 
//$pdf->SetSubject('TCPDF Tutorial'); 
//$pdf->SetKeywords('TCPDF, PDF, example, test, guide'); 

$pdf->SetHeaderData(PDF_HEADER_LOGO, PDF_HEADER_LOGO_WIDTH, PDF_HEADER_TITLE.' 049', PDF_HEADER_STRING); 

$pdf->setHeaderFont(Array(PDF_FONT_NAME_MAIN, '', PDF_FONT_SIZE_MAIN)); 
$pdf->setFooterFont(Array(PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA)); 

$pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED); 

$pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT); 
$pdf->SetHeaderMargin(PDF_MARGIN_HEADER); 
$pdf->SetFooterMargin(PDF_MARGIN_FOOTER); 

$pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM); 

$pdf->setImageScale(PDF_IMAGE_SCALE_RATIO); 

if (@file_exists(dirname(__FILE__).'/lang/eng.php')) { 
    require_once(dirname(__FILE__).'/lang/eng.php'); 
    $pdf->setLanguageArray($l); 
} 
$pdf->SetFont('helvetica', '', 10); 

$pdf->AddPage(); 
//$html = '<h1>Test TCPDF Methods in HTML</h1> 
//<h2 style="color:red;">IMPORTANT:</h2> 
//<span style="color:red;">If you are using user-generated content, the tcpdf tag can be unsafe.<br /> 
//You can disable this tag by setting to false the <b>K_TCPDF_CALLS_IN_HTML</b> constant on TCPDF configuration file.</span> 
//<h2>write1DBarcode method in HTML</h2>'; 
$pdf->writeHTML($html, true, 0, true, 0); 

$pdf->lastPage(); 
ob_end_clean(); 
$pdf->Output('example_049.pdf', 'I'); 
header('Content-type: application/pdf'); 
header('Content-Disposition: inline; filename="file.pdf"'); 
header('Content-Transfer-Encoding: binary'); 
header('Content-Length: ' . filesize('customer-receipts-report.pdf')); 
header('Accept-Ranges: bytes'); 
readfile('customer-receipts-report.pdf'); 
ob_end_flush(); 

請人幫我在這個問題上。

+0

我認爲有一些問題與循環或可能是大量的記錄。 –

回答

4

在你的代碼

set_time_limit(0);

加入這一行,這

ini_set('memory_limit', '-1'); //它不是妥善的解決辦法,但它會做的伎倆。

或者

ini_set('memory_limit', '640M'); //設置正確的內存限制在你的PHP文件

+0

我試過這個。所以我得到空白頁面,並且第一個錯誤不會出現。致命錯誤:顯示134217728字節允許內存大小用盡(試圖分配1961字節)錯誤。 –

+0

Thanks.It現在通過設置ini_set('memory_limit','-1')來工作;但是它需要一些時間,它會被減少。 –

+0

而不看你的代碼,不,並且對於1000條記錄它應該需要時間或者可能會有while循環的一些問題。如果答案解決了您的問題,請將其標記爲正確。 – Shehary

相關問題