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

RealWorldDev's avatar

Horizon picking up jobs from wrong site

I have some weird behaviour with Horizon running on AWS and using Forge. I'll try and keep this simple(!) but here goes:

  • I have one server with running 2 sites
  • Both sites use Horizon
  • When a job is run on site A, Horizon on site A picks it up and the job runs ok
  • However, Horizon on site B also picks up the job and mimics the exact same as Horizon on site A, even though it's a completely different site
  • When a job is run on site B, absolutely nothing happens at all. No jobs are processed and Horizon on site B just sits motionless

In a nutshell, Horizon on site A is picking up jobs from it's own site and another site on the same server and any jobs on site B are completely ignored from being processed by Horizon on site B. It's like both Horizons on both sites are sharing the same app but only running jobs from one site. Not ideal as Horizon from site B can see jobs running on a completely different site that is nothing to do with it, but completely ignoring it's own!

Has anyone seen this behaviour at all? Have I misinterpreted how this all works? Obviously it's not good for a site to see another site's jobs but also not good that the other site's jobs aren't running at all.

Really hope all that makes sense!

0 likes
2 replies
LaryAI's avatar
Level 58

It sounds like both of your Horizon instances are using the same Redis database and queue name, which is why jobs dispatched on one site are being picked up by both Horizon instances. To resolve this issue, you need to ensure that each site has its own unique queue configuration.

Here are the steps you can take to fix this issue:

  1. Configure Separate Redis Databases or Prefixes: Each site should use a different Redis database or a unique prefix to prevent collision.

    For example, in your .env file for each site, you can specify a different Redis database:

    Site A:

    REDIS_DB=0
    

    Site B:

    REDIS_DB=1
    

    Or use different prefixes:

    Site A:

    REDIS_PREFIX=site_a_database_
    

    Site B:

    REDIS_PREFIX=site_b_database_
    
  2. Unique Horizon Environments: Make sure that each site has a unique Horizon environment specified in the config/horizon.php configuration file.

    For example:

    Site A:

    'environments' => [
        'production' => [
            // ...
        ],
        'site_a' => [
            'supervisor-1' => [
                'connection' => 'redis',
                'queue' => ['site_a_queue'],
                'balance' => 'simple',
                'processes' => 10,
                'tries' => 3,
            ],
        ],
    ],
    

    Site B:

    'environments' => [
        'production' => [
            // ...
        ],
        'site_b' => [
            'supervisor-1' => [
                'connection' => 'redis',
                'queue' => ['site_b_queue'],
                'balance' => 'simple',
                'processes' => 10,
                'tries' => 3,
            ],
        ],
    ],
    
  3. Run Horizon with the Correct Environment: When you start Horizon, make sure to specify the correct environment for each site.

    For Site A:

    php artisan horizon --environment=site_a
    

    For Site B:

    php artisan horizon --environment=site_b
    
  4. Dispatch Jobs to the Correct Queue: When dispatching jobs, make sure to specify the correct queue that corresponds to the site.

    For Site A:

    dispatch((new YourJob)->onQueue('site_a_queue'));
    

    For Site B:

    dispatch((new YourJob)->onQueue('site_b_queue'));
    

By following these steps, you should be able to isolate the Horizon instances and queues for each site, preventing them from picking up each other's jobs. Make sure to restart the Horizon service after making these changes to apply the new configuration.

RealWorldDev's avatar

Thank you AI bot QuickDraw, it did help a little bit but now...

  • Site B can now process jobs but nothing shows up in the Horizon dashboard
  • Site A has now stopped processing jobs and it doesn't even report any queues in the Horizon dashboard

All was working perfectly fine with just one site on the server but add a second that also needs Horizon and it seems to be a config nightmare. I'll keep trying and post back with any updates I'm not confident right now!

Please or to participate in this conversation.