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

zelaza's avatar

Environment variables go CRAZY on queued jobs?

I'm seeing very weird behavior when trying to access environment variables from queued jobs (on Laravel Forge, nginx web server, using beanstalkd for queues).

I have a .env file with lots of variables in it.

When I try to access environment variables from my queued Job, I get incredibly strange results, e.g.:

  • A FEW environment variables act as expected
  • MOST environment variables are not available
  • and, the strangest of all, SOME environment variables come back with wrong, unexplainable values

My .env file looks like:

APP_ENV=local
APP_KEY=base64:7QnDA97sxhgxhjxghjxgjhxc9wrrrVHiUvVW7sH/BzOqGXImTU9BY=
APP_DEBUG=true
APP_LOG_LEVEL=debug

TEST=testval
FACEBOOK_APP_ID=8763846876763
MY_FACEBOOK_APP_ID=whatever

# many other environment variables defined here (not shown)
...

TWITTER_CONSUMER_KEY=khskshiusyisuyisuy
TWITTER_CONSUMER_SECRET=ioudousouodius
TWITTER_ACCESS_TOKEN_SECRET=hgfcxhgfchgvfghcfvhgfc

And when I dump $_ENV from inside the Job, I get:

'TEST' => 'testval', 
'MY_FACEBOOK_APP_ID' => 'whatever', 
'TWITTER_ACCESS_TOKEN_SECRET' => 'hgfcxhgfchgvfghcfvhgfc'

So:

  • TEST and MY_FACEBOOK_APP_ID are present and correct
  • Many environment variables, including FACEBOOK_APP_ID, have simply disappeared from $_ENV
  • TWITTER_ACCESS_TOKEN_SECRET, the last variable in the .env file, is present and correct

And now, for the freaking weirdest thing of all...

When I do env('FACEBOOK_APP_ID') from inside the job, I get a a wrong, inexplainable value that's different from 8763846876763

Can anyone explain what's going on?

0 likes
4 replies
zelaza's avatar

Does anyone have any thoughts on this? Seems pretty important - your config and env variables do weird, unexplainable things when accessed from inside queued jobs...?

Any help?

pflirae's avatar

I have the same problem, did you find any solution ??

helmerdavila's avatar

I just restarted my server, and works (?). If you have some errors in the queue, maybe you need to purge the queue.

Cronix's avatar

Also, any time you make changes to your code, you need to restart the queue workers or the queue won't know about them.

Please or to participate in this conversation.