Running Multiple Instances of Laravel Horizon on the Same Server

Original - Sep 23, 2019 - 1 minute read
Running Multiple Instances of Laravel Horizon on the Same Server

In this blog we'll go over the process of running multiple instances of Laravel Horizon on the same server.
If you're like me you tend to have a staging and production instance of your code on the same server. Recently I've been running into an issue where my Laravel Horizon queues were not processing when I had multiple instances of Horizon on the same server. Here's how I fixed that issue:

In your config/horizon.php file you'll need to create a new environment for your staging environment. There should be one for local and production already but nothing for staging. Create that

 'staging' => [
  'supervisor-staging' => [
    'connection' => 'redis',
    'queue' => ['queue.staging'],  // Use a unique name for your staging queue
    'balance' => 'simple',
    'processes' => 3,
    'tries' => 3

Once that is done we'll want to use a different Redis database than our production application uses so we don't have any collisions with the queues. Head over to your config/database.php file and add some values under the redis option.

'options' => [
  'prefix' => env('REDIS_PREFIX', 'prod:')

The last step is to edit your .env file and add some references to your staging queues. You'll need to define a REDIS_QUEUE key/value pair as well as some other key/value pairs for Redis.



That should be all you need to separate your Laravel Horizon instances on the same server.