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

moe3615's avatar

Set Horizon environment

I'm hoping someone can help me with this.

I have several servers running my queues using Horizon and Redis. All servers are in production enviroment and sharing the same codebase.

I'm trying to ensure that certain EC2 servers only run specific queues and have unique configurations. I know I can add custom enviromnet in Horizon.php which will get the environment from th .env file. But is there any other way to do this?

What ideally I'm looking to do is something along these lines.

In the .env file add a new line called "SERVER_NAME=SERVER1" and in config/horizon.php I want to set unique environment for each server based on the SERVER_NAME environment variable.

Or is there any other recommended way of doing this?

In summary: All servers must share the same code base. It doesn't sound like a good idea to give each server a unique environment name (APP_ENV=local) I want each server to run only specific queues

Any feedback or recommendation would be very much appreciated.

0 likes
4 replies
Snapey's avatar

so each server will have its own .env file

Then just pull the value from env in the horizon config file ... same as any other env parameter?

The config file just returns an array, you can put logic in there such as a switch statement

1 like
moe3615's avatar

I didn't think of doing that.

You think something like this will work:

Instead of

'environments' => [
    'production' => [
        'supervisor-1' => [
            'maxProcesses' => 10,
            'balanceMaxShift' => 1,
            'balanceCooldown' => 3,
        ],
    ],
],

I can do this?

'environments' => [
    env('SERVER_NAME') => [
        'supervisor-1' => [
            'maxProcesses' => 10,
            'balanceMaxShift' => 1,
            'balanceCooldown' => 3,
        ],
    ],
],

If this is what you mean, I'll certainly test this

Snapey's avatar

i dont see what you are changing

all the servers are in production but by this you will need to specify them differently ie not production yet they all get the same parameters

don't you need to alter the queues.php?

Snapey's avatar

i would expect more like this

'environments' => [
    'production-alpha' => [
        'supervisor-1' => [
            'connection' => 'redis',
            'queue' => ['default', 'emails'],
            'balance' => 'auto',
            'minProcesses' => 1,
            'maxProcesses' => 10,
            'balanceMaxShift' => 1,
            'balanceCooldown' => 3,
            'tries' => 3,
        ],
   'production-beta' => [
        'supervisor-1' => [
            'connection' => 'redis',
            'queue' => ['images','videos'],
            'balance' => 'auto',
            'minProcesses' => 1,
            'maxProcesses' => 10,
            'balanceMaxShift' => 1,
            'balanceCooldown' => 3,
            'tries' => 3,
        ],
    ],

],

and then set APP_ENV to production-beta or production-alpha or whatever you want to call your environments

Please or to participate in this conversation.