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

princeparaste's avatar

On changing Listener code its not changing. Laravel always using cached code.

I am sending Mails in queues via events and listener. But whenever i change some code in my Listener file is not getting deducted by laravel. It is always using the old cached version of code i think.

Because when i change the filename, the new code works. But when i make change and dont rename the file. it didnt detect that my code is being changed.

I also tried using php artisan cache:clear but no luck

0 likes
8 replies
princeparaste's avatar

Thanx @martinbean. restarting the worker but. do you know how can i auto restart it everytime i make a file change ? I am using pm2 process to keep track of queue jobs.

https://www.npmjs.com/package/pm2

It automatically starts when i php artisan serve But it didnt restart it when i make a file change.

This is my YML file for pm2 :

apps:
  - name: laravel-queue-worker
    script: artisan
    exec_mode: fork
    interpreter: php
    instances: 1
    args:
      - queue:work
      - --tries=5
      - --sleep=1
martinbean's avatar

@princeparaste I have no idea what that package is. I’ve never used it.

You need to restart the worker each time you make a code change because the queue worker process loads the application into memory. So changing code does not change what’s in memory for the running process.

It automatically starts when i php artisan serve

Please tell me you’re not using php artisan serve to serve your application in a production environment…?

princeparaste's avatar

@martinbean No i am not, 😂 I am just using that cmd in my Local. This queue worker method is effective to send mail in queue. But i don't know what will happen if some other developer will code on my project. He might not know pm2 process needs to be restart everytime the file change.

princeparaste's avatar

@Snapey Not sure about two minutes. sometime i change code too frequent to debug issues. but will try

newbie360's avatar

@princeparaste

you may try php artisan queue:listen

https://laravel.com/docs/8.x/queues#the-queue-work-command

Alternatively, you may run the queue:listen command. When using the queue:listen command, you don't have to manually restart the worker when you want to reload your updated code or reset the application state; however, this command is significantly less efficient than the queue:work command:

1 like

Please or to participate in this conversation.