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

amir5's avatar
Level 7

Is there any way to read fresh config values in queue:work

When I run a job that uses a config(env) variable's value, when I change that value in .env, to have fresh values in my job, I have to restart the queue:work, is there any other way that I don't need to check that I've changed .env or not, to restart queue(on deploy)?

0 likes
7 replies
tykus's avatar
tykus
Best Answer
Level 104

The queue worker initiated using php artisan queue:work is a long-running process so it needs to be restarted whenever there is a change to your code/environment. This is the most efficient way to run queues on your production environment.

However, if you use the queue listener, initiated by php artisan queue:listen instead, it will not require restarting after changes in your code/application state.

I would wonder why your environment variables are needing to be changed at all? What is the underlying issue here

amir5's avatar
Level 7

@tykus e.g, adding a new job that requires a .env variable to a deployed application, or modifying wrong(or updated) .env values(external url addresses), and etc.

tykus's avatar

@amir5

adding a new job

Adding a new Job class will also require deployment; restarting PHP-FPM as well as the queue worker.

modifying wrong .env value

Surely this is not a regular problem?

Why is restarting the queue worker during these maintenance activities difficult?

Last thing... typically .env variables are cached into your config, and once config is cached, the .env file is not read. In fact, it is recommended not to use the env() helper outside of your config files; how are you handling this aspect of changing env variables?

amir5's avatar
Level 7

@tykus by using .env, I mean using them via config

restarting PHP-FPM as well as the queue worker.

Should I? why restarting PHP_FPM? currently I have a deploy script that just pulls, installs, optimize:clear, optimize, and other stuff.

tykus's avatar

@amir5 do you use opcache at all; reloading PHP-FPM will flush the opcache.

Snapey's avatar

remember not to try and use env values anywhere other than in config files, and then use config in your code.

1 like

Please or to participate in this conversation.