Maximum Execution time of 30 Seconds exceeded MPDF

Asked

Viewed 2,020 times

2

When running local the PDF generates normally, but on the server it exceeded the time limit and does not open.

<?php 

        require_once "../mpdf60/mpdf.php";
        require_once "../DAO/conexao.php";
        require_once "../DAO/vendaDAO.php";
        session_start();

        $vend = $_SESSION["vendedor_nome"];


        if (isset($_GET["orcamento"]) && isset($_GET["data"]) && isset($_GET["cliente"]) && isset($_GET["totalprod"]) && isset($_GET["email"]))
        {
                $orcamento = $_GET["orcamento"];
                $data = $_GET["data"];
                $cliente = $_GET["cliente"];
                $totalprod = $_GET["totalprod"];
                $email = $_GET["email"];

                $dao = new VendaDAO();
                $venda = $dao->GetByIdRel($_GET["orcamento"]);
                $itens = $venda->getItensRel($venda);

                foreach($itens as $item)
                {

                    $formaPagamento = $item->getCusto($row->FPG_DESCRICAO);
                }




                $html = " 

                <hr> </hr>
                <div id='img'> <img src='../css/logo.png' align='center' height='100px' width='220px' ></div>
                 <div id='teste'>
                        <td> Rua X, y 
                        Centro - CIDADE/UF 
                        CEP: 10000-000 <br/>
                        (00) 3333.3333 | E-mail
                        [email protected]
                     </div>
                    <hr> </hr>
                    <p align='center'><b> DADOS DA VENDA </b></p>
                    <p></p>


                                    Número do Pedido: $orcamento <br/>
                    Data da Venda: $data  <br/>
                                    Vendedor: $vend <br/>
                                    Cliente: $cliente <br/>
                                    Email: $email <br/>
                                    Forma de Cobrança: $formaPagamento  <br/>
                                    Total Produtos: $totalprod <br/>    
                                    <hr> </hr>    
                    <p align='center'><b> DADOS DO PRODUTO </b></p>



                    <table border=1 align='center' cellspacing='0'>
                    <tr>
                    <td><b>PRODUTO</b></td>
                    <td><b>DESCRIÇÃO</b></td>
                                    <td><b>QUANTIDADE</b></td>
                                    <td><b>VALOR</b></td>
                    <td><b>TOTAL</b></td>";




                                 foreach($itens as $item)  
                                 {
                                        $produto = $item->getProduto();

                                            $html= $html ."<tr>
                                            <td>{$item->getProduto($row->PRO_CODIGO)}</td>
                                            <td>{$item->getReservado($row->PRO_DESCRICAO)}</td>
                                            <td>{$item->getQuantidade($row->ORI_QTDE)}</td>
                                            <td>{$item->getValor($row->ORI_VALOR)}</td>
                                            <td>{$item->getTotal($total)}</td>
                        </tr>";
                                 }
                    $html = $html . "</table>";




                                    $mpdf=new mPDF(); 
                                    $html = mb_convert_encoding($html, 'UTF-8', 'UTF-8');
                                    $mpdf->SetDisplayMode('fullpage');
                                    $css = file_get_contents("css/estilo.css");
                                    $mpdf->WriteHTML($css,1);
                                    $mpdf->WriteHTML($html);
                                    $mpdf->Output();

        }
    ?>
  • 1

    Try to use ini_set('max_execution_time', 60); and see if it can be used as a solution. Place it well in the code header. Ideally, you can change it in php.ini for standardization (PSR).

  • Perfect guy, worked here with mine. Thanks and congratulations

1 answer

2

Place at the beginning of the file set_time_limit(0);

set_time_limit sets a maximum execution time for a script, but if you set it to 0 no limit is set.

(see the PHP documentation)

  • I set set_time_limit(0); and it worked, but it’s taking about 50 seconds to execute.. Do you have a method that makes this execution faster? This is because the library is heavy?

  • @B.Noe with respect to speed is a little more complicated because there is a "N" possibility of things that can make the code slow down, from library to server configuration. But if this answer helps you please mark as solved! :)

Browser other questions tagged

You are not signed in. Login or sign up in order to post.