mikehaertl / phpwkhtmltopdf

A slim PHP wrapper around wkhtmltopdf with an easy to use and clean OOP interface
MIT License
1.6k stars 238 forks source link

PDF Generation Slow in Production Environment #143

Closed beasknees closed 8 years ago

beasknees commented 8 years ago

In my local vagrant environment pdf generation takes only about 2 seconds: image

We also have a development server which has similar results: image

However on the production server it takes over 40 secs. image

All servers use Ubuntu 14.04 and Apache 2.4.7. The only difference seems to be that the production server is behind a load balancer.

This is the setup I am using:

public function pdf(){
        $title = $this->input->post('export_title', TRUE);
        $data['title'] = preg_replace('/_/', ' ', $title);

        $templateID = $this->input->post('export_template_id', TRUE);
        $answerID   = $this->input->post('export_answer_id', TRUE);
        $data['form'] = $this->getAnsweredForm($templateID, $answerID);

        $html =  $this->load->view('pdf/header', '', true);
        $html .= $this->load->view('pdf/view_custom_form', $data, true);

        $pdf = new mikehaertl\wkhtmlto\Pdf(array(
            // Explicitly tell wkhtmltopdf that we're using an X environment
            'use-xserver',

            // Enable built in Xvfb support in the command
            'commandOptions' => array(
                'enableXvfb' => true,
        )));

        $pdf->addPage($html);

        if(!$pdf->send("$title.pdf")){
            echo $pdf->getError();
        }
    }

I've also tried just passing in 'google.com' with similar results. We use CodeIgniter and I tried passing in the URI of a page which resulted in it being generated appropriately on my vagrant but 'Failure without error message' on the production server.

Any debugging tips would be greatly appreciated. I've looked and haven't found anyone with similar issues, so I was hoping you could help here.

mikehaertl commented 8 years ago

Sorry, no idea. I also don't think, that this is a bug or something we could fix here. So I'm closing this.