1

I am using a Laravel job which handles specific registration confirmations via mail.

In the handle() function of the job I am referring to another class' static function (TicketController) which generates a PDF:

public function handle()
{
    $this->ticket = TicketController::createPdf($this->customer);

    Mail::to($this->customer->email)->send(new CustomerAccepted($this->customer, $this->ticket));
}

If I run this job via sync driver everything is just working fine. But with database I always get the error

class 'PDFlib' not found

Of course the class is implemented in my TicketController and I also tried implementing it directly into my job class.

I also tried restarting the queue worker several times but I always get the same result when running with database.

EDIT:

TicketController.php:

use App\Customer;
use PDFlib;

class TicketController extends Controller
{
    public function createPdf(Customer $customer) 
    {
        $p = new PDFlib();

        $p->set_option("errorpolicy=return");
        $p->set_option("stringformat=utf8");
        $p->set_option("searchpath={" . resource_path() . "assets/fonts" . "}");
        $p->set_option("spotcolorlookup=false");

        if ($p->begin_document(storage_path('app/xy.pdf'), "") == 0) {
            echo ("Error: " . $p->get_errmsg());
            exit(1);
        }
        // Loading template and filling with content

        $p->end_page_ext("");
        $p->end_document("");

        return storage_path('app/xy.pdf');
    }
}

EDIT #2

I added the complete PDFlib function directly to the handle() of the job but still getting the same error class 'PDFlib' not found.

EDIT #3

Just realized that running the driver database locally and listen to queues with php artisan queue:listen is working perfectly fine.

I am running the application on Laravel Forge and also database driver. Tried to set up the queue with daemon worker and without but neither setting works.

Mango D
  • 501
  • 3
  • 11
  • 28
  • 1
    Could we see the TicketController? – Mozammil Jan 21 '19 at 16:37
  • Yeah, we're going to need to see where you're actually using PDFlib. Given that it doesn't work in a queued job but works in an unqueued version, I'd bet it's something about being unable to serialize a PDFlib instance properly. – ceejayoz Jan 21 '19 at 16:40
  • I added `TicketController` – Mango D Jan 21 '19 at 16:46
  • @MangoD So, a couple things. First, `createPdf` doesn't return anything. If that bit's just not shown, I suspect what's happening is Laravel is serializing the `$p` object, but that PDFlib doesn't support that. Instead of setting it to `$this->ticket`, try generating it on-the-fly in the `handle()` function. – ceejayoz Jan 21 '19 at 18:45
  • @ceejayoz Oh right. I added the returned value. It is just a path to the created file from PDFlib. Okay, I will try to add the function directly in the `handle()` method. – Mango D Jan 22 '19 at 07:59
  • @ceejayoz Edited my question. Had no luck with adding the `PDFlib` method to the job. – Mango D Jan 23 '19 at 18:51

0 Answers0