Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

master_chief_sunday's avatar

How to properly debug Jobs in Laravel 5

Hi guys,

This is bugging me for a very long time. I have another project on my hand with Jobs.

I have PHPStrom, Sublime, CentOS7, PHP 7.2 installed.

Now here is the real life example.

Before sending the DTO to Google Sheet for writing on run-time that means in handle() method I get the data for DTO from the DB, there is something nothing returning as is should so I want ot debug it.

Without going into handle() method and write each print_r() and rerun the job over and over again, and inspect what I got returned, it's just pain in both time and efficiency in my eyes.

So I wonder if somebody in the world out there has some best practice how to deal with this debugging of jobs in Laravel in conjunction with perhaps PhpStorm?!

Question is simple: How to properly debug Jobs in Laravel 5, TBH I believe answer is not that easy.

Thank you in advance for your time, Matija

0 likes
11 replies
phpMick's avatar

Can't you just use xDebug and stick a breakpoint in the job?

master_chief_sunday's avatar

hello phpMick,

The answer to your questions is sadly NO!

exactly that is the whole point of it. You create and dispatch the job in Laravel. Then sits on the queue and they you run it. For i.e. I have configured database for queue worker in .env => QUEUE_DRIVER=database. So I run it with the command in terminal:

php artisan queue:work --tries=3 --timeout=500 --queue=checkouts,mail

Here is the output in terminal:

$ pa queue:work --tries=3 --timeout=500 --queue=checkouts,mail
[2018-01-24 20:50:23] Processing: App\Jobs\OrderCompleted
- Order #11#, Customer #1#
[2018-01-24 20:50:23] Processed:  App\Jobs\OrderCompleted
[2018-01-24 20:50:23] Processing: App\Jobs\WriteOrderToGoogleSheet
[2018-01-24 20:50:28] Processed:  App\Jobs\WriteOrderToGoogleSheet
[2018-01-24 20:50:28] Processing: App\Jobs\SendOrderToCRM
[2018-01-24 20:50:28] Processed:  App\Jobs\SendOrderToCRM
[2018-01-24 20:50:28] Processing: App\Jobs\SendPurchasedEmail
Session id:nw0viZvwM2JQo2yeYjX8V8XozvmxP43zrhSXZJxi Current FROM EMAIL Address after overload: [email protected]
Session id:nw0viZvwM2JQo2yeYjX8V8XozvmxP43zrhSXZJxi Current success email parameters: {"checkout":{"customer_id":1,"first_name":"APPROVED by Matija","last_name":"Baric","email":"[email protected]","address":"ABC","city":"ABC1","zip":"4123","country":"BR","locale":"br","order_id":11,"price":585,"price_parsed":585,"quantity_parsed":5,"currency":"BRL","reference_number":null,"payment_status":"CO","tracking_number":null,"order_item_id":22,"product_name":"SMOOTHTOUCH","sku":"SMOOTHTOUCH-5","requires_shipping":"1","taxable":"1"},"upsell1":{"upsell1_price_parsed":"33.00","upsell1_quantity_parsed":"1"},"upsell2":{"upsell2_price_parsed":"150.00","upsell2_quantity_parsed":"1"},"upsell3":{"upsell3_price_parsed":"57.00","upsell3_quantity_parsed":"1"}}
[2018-01-24 20:50:30] Processed:  App\Jobs\SendPurchasedEmail

You can clearly see after 2018-01-24 20:50:28] Processing: App\Jobs\SendPurchasedEmail there is a print_r($objectToPrint) and output.

So the queue actually run in the terminal, on production you run it with supervisor or Amazon SQS.

So my initial question is how to debug this on runtime of the job? Let me know if something needs to be clarified in more detail, please.

Drfraker's avatar
Drfraker
Best Answer
Level 28

You can debug jobs easily by setting the queue driver to sync. Instead of being queued they will run synchronously. Then you can use xDebug.

12 likes
oaj's avatar

I would stick a bunch of Log::debug statements in the handler instead of print_r.

master_chief_sunday's avatar

@phpMick @Drfraker I'll give it a test with this QUEUE_DRIVER=sync locally and let you know, have some important stuff to work on now, bull I'll get back ASAP. thanks to all.

1 like
master_chief_sunday's avatar

Hello guys. @Drfraker thank you for your reply, this one stands and it's working with PhpStrom and xDebug.

In .env: QUEUE_DRIVER=sync

Put a brakpoint in the handle() function run you application and when the Job will be processed the breakpoint will raise and you can debug.

Thanks to all.

2 likes
tpane24's avatar

@drfraker , I am unable to set my queue driver to sync because the job is queued by a different part of the app. What would be the best way to debug the job when the queue driver is set to database?

Please or to participate in this conversation.