mercredi 30 décembre 2015

Mail Queue and DOMPDF job works perfectly on homestead, but not on my production server

Latest 5.1 Laravel 5.1.27 Latest dompdf 0.6.2

So i have an email, that attaches a generated PDF, that is queued.

Tested on homestead, both manually with artisan:work and artisen:listen, it all works well, i receive the email perfectly with the attached PDF.

Only in my production server, that has same parameters, at least for what i can see, doesnt work!!

It all works if synchronously with Mail::send

When updated to Mail:queue, i get the Job stuck, on production i have supervisor with artisan:listen --tries=10 and it gets failed, and moved to the failed_jobs table.

Aah, mail::queue workes perfectly if without PDF attachment

So i could nail it down to the exception thrown by DOMPDF, only in production and only in a queued job!

exception 'ErrorException' with message 'Undefined index: SCRIPT_FILENAME' in /home/myapp_name/vendor/dompdf/dompdf/include/stylesheet.cls.php:147

So this line on stylesheet.cls.php:147 is

list($this->_protocol, $this->_base_host, $this->_base_path) = explode_url($_SERVER["SCRIPT_FILENAME"]);

So all comes down to being on CLI (command line interface), that doesn't have this $_SERVER["SCRIPT_FILENAME"] defined!!

All would make sense to go down this road, but why the heck does it work perfectly when job processed in homestead, also on CLI??

Hope i make sense!! Code for the queue

$data = [bla bla bla]; // this $data is for the blade render, and is different from the one used in the Closure, for the PDF, i know =)
    Mail::queue('emails.default', $data , function($message) use ($destinatarios, $user_spo_full_name, $spare_part_order, $spare_parts_order_list)
    {
        $message->to($destinatarios);
        $message->subject('Spare Part Order Confirmation - Your ref: ' . $spare_part_order->client_reference );

        $data =
            [
                'user_full_name' => $user_spo_full_name,
                'spare_part_order' => $spare_part_order,
                'spare_parts_order_list' => $spare_parts_order_list
            ];
        $pdf = PDF::loadView('spareparts.sparepartsorder.pdf.spare-part-order', compact('data'));
        $message->attachData($pdf->output(), 'SP_'.$spare_part_order->client_reference . '.pdf' );

    });

Thanks in advance for any help and happy new year all!!



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire