me108's avatar
Level 1

Job fails silently on exception, nothing is logged

I have a weird issue with my Laravel 10 project on Windows 11.

When a job throws an exception, Laravel just quits silently without logging anything to /storage/logs/laravel.log. It also ignores try-catch blocks and quits the execution nontheless.

It wasn't always like that. It worked in the past. But I can't remember when it stopped and what I might have changed, except from adding / removing some packages.

This problem effects only Jobs. Exceptions that may occur in Controllers are handled properly. They are either thrown or caught and are logged to the laravel.log file.

/app/Jobs/TestJob.php

C:\Work\MyProject>php artisan:test

Which command would you like to run?
  App\Jobs\TestJob ..................................................... 0
❯ 0

  Running [App\Jobs\TestJob]
C:\Work\MyProject>

When I create a single PHP file in the folder with the same exception and run it via php -f exception.php it works as expected:

C:\Work\MyProject>php -f .\exception.php

There was an exception which was caught.
C:\Work\MyProject>

When I use a different environment (MacOS, Ubuntu) and run the same scenario, it works as expected aswell.

user@MyMacBook MyProject % ./artisan schedule:test

  Which command would you like to run?
  App\Jobs\TestJob

  Running [App\Jobs\TestJob] There was an exception which was caught. ....................... 19ms DONE

user@MyMacBook MyProject % 

I already tried switching PHP versions. On Windows I run PHP 8.3.14. On MacOS it is 8.2.4. But without success.

What could be the issue here?

0 likes
5 replies
Talinon's avatar

@me108 What is your queue driver on the windows instance? Check the QUEUE_CONNECTION setting in your .env. If it's set to sync on the other instances it might explain why you're seeing the output as it'll immediately run the job. If it's set to something else on Windows, it'll be queued and sent to a background worker so you won't see the echo within the terminal.

me108's avatar
Level 1

@Talinon Thank you. I checked it. In both environments (Windows and MacOS) QUEUE_CONNECTION is set to sync.

me108's avatar

If anyone stumbles upon this thread because they have the same issue, I finally found the cause:

Installing WAMP enabled the xdebug extension in the php.ini and that caused the issue. Setting xdebug.mode=off and restarting the WAMP services fixed the problem.

Snapey's avatar

running out of memory is the main cause of php crashing with no error handling. Maybe turning debug off gave you a little more headroom, but the issue might still be lurking there just waiting for you to add some more complexity,

1 like
me108's avatar

I remember it was working fine before. Then at some point I updated WAMP and didn't notice it first because at that time I wasn't working on jobs on the Windows 11 machine. Only later at some point I noticed it when adding features to a job and testing them that no exception was thrown and PHP quit silently. As mentioned in the OP it already failed silently when forcing a simple exception like division by zero. So I think it wasn't an out of memory issue. Also the same (faulty) code produced an exception output and log on a different machine (Mac).

Please or to participate in this conversation.