High consumption and slowness with DOMPDF

0

Good using DOMPDF to generate a PDF report from an HTML table.

I'm having a very big problem where DOMPDF is using an average 4.4GHz processor and 1GB of ram and taking more than 5 minutes to render a table with 850 rows.

I do not know if this is normal, but I'm finding a lot of time and a lot of consumption.

I'll post an example of how my code is.

    <?php
// Ativa o buffer de saída
ob_start();

// Aqui eu monto o array com os dados do BD
//$relatorio = array('');
?>

<html>
    <head>
    <meta charset="UTF-8">
    <title>RELATÓRIO</title>
    </head>
    <body>

        <!-- Relatório -->
        <table class="relatorio">

            <caption>
                RELATÓRIO DE USUÁRIOS. GERADO EM: <?= date('d/m/Y') ?> (<?= date('H:i') ?>)
            </caption>

            <thead>
                <tr>
                    <td>IDADE</td>
                    <td>USUÁRIO</td>
                    <td>ENDEREÇO</td>
                </tr>
            </thead>

            <tbody>
                <?php
                // Navega pelos elementos do array
                foreach ($relatorio as $c) {
                    ?>
                    <tr>
                        <td><?=$c['idade']?></td>
                        <td><?=$c['nome']?></td>
                        <td><?=$c['endereco']?></td>
                    </tr>
                    <?php
                }
                ?>
            </tbody>
        </table>
    </body>
</html>

<?php

// Recebe o HTML da página
$html = ob_get_clean();

// Regista auto loader
include 'autoload.inc.php';
Dompdf\Autoloader::register();

// Referencia o namespace Dompdf
use Dompdf\Dompdf;

/* Cria a instância */
$dompdf = new Dompdf();

$dompdf->set_paper('A4', 'portrait');

/* Carrega seu HTML */
$dompdf->loadHtml($html);

/* Renderiza */
$dompdf->render();

/* Exibe */
$dompdf->stream(
    "Cadastros.pdf", /* Nome do arquivo de saída */
    array(
        "Attachment" => false /* Para download, altere para true */
    )
);

I've done a lot of testing and the problem really is when DOMPDF comes into play, if anyone knows of any way to improve performance I'll be very grateful.

    
asked by anonymous 27.04.2018 / 02:53

0 answers