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

Thumbtech's avatar

Laravel 10 app running on 2 servers ... how to dispatch redis jobs from one to other

The identical apps are running @ forge with local redis queues (w/ horizon workers) on the two servers and the queues are running fine with horizon monitoring/reporting etc.

I thought it would be a simple matter to dispatch a job from one server to another after:

  1. make sure network access to queue was available & testing with redis-cli, etc.
  2. config new redis database with host IP & password in database.php
  3. config new redis connection with above redis DB connection in queue.php
  4. dispatch or push job to new redis connection.

In principle should that do it? Obviously I am here because it isn't working for me. Debugging this is tough if, like me, you are not comfortable with the guts of Redis DB's.

I can provide some hello world code, but hoping somebody will have some idea that this cannot be done because ____ or it can be done but you must also ____ :-)

0 likes
5 replies
LaryAI's avatar
Level 58

To dispatch jobs from one Laravel application to another using Redis, you need to ensure that both applications are configured to use the same Redis server and database for their queues. Here's a step-by-step guide to achieve this:

  1. Ensure Network Access: Make sure that the Redis server is accessible from both servers. This might involve configuring your firewall to allow traffic on the Redis port (default is 6379) from the IP addresses of both servers.

  2. Configure Redis in database.php: In your config/database.php file, set up a new Redis connection that points to the shared Redis server. For example:

'redis' => [

    'client' => env('REDIS_CLIENT', 'predis'),

    'options' => [
        'cluster' => env('REDIS_CLUSTER', 'redis'),
        'prefix' => env('REDIS_PREFIX', Str::slug(env('APP_NAME', 'laravel'), '_').'_database_'),
    ],

    'default' => [
        'url' => env('REDIS_URL'),
        'host' => env('REDIS_HOST', '127.0.0.1'),
        'password' => env('REDIS_PASSWORD', null),
        'port' => env('REDIS_PORT', '6379'),
        'database' => env('REDIS_DB', '0'),
    ],

    // Add your new Redis connection here
    'server2' => [
        'host' => 'ip_of_the_other_server',
        'password' => 'password_for_redis_on_other_server',
        'port' => '6379',
        'database' => '1', // Use a different database number if needed
    ],
],
  1. Configure Queue Connection in queue.php: In your config/queue.php file, create a new queue connection that uses the Redis connection you just configured:
'connections' => [

    // ... other queue connections ...

    'redis-server2' => [
        'driver' => 'redis',
        'connection' => 'server2',
        'queue' => env('REDIS_QUEUE', 'default'),
        'retry_after' => 90,
        'block_for' => null,
    ],
],
  1. Dispatch the Job: When dispatching a job, specify the connection you want to use:
dispatch((new YourJob())->onConnection('redis-server2'));

Or, if you're using the dispatch function:

dispatch(new YourJob())->onConnection('redis-server2');

Make sure that:

  • The Redis server is not bound to 127.0.0.1 in its configuration file (redis.conf), as this will prevent external connections. It should be bound to 0.0.0.0 or the specific server IP that other servers can access.
  • The Redis server has a strong password if it's exposed to the internet or an untrusted network.
  • Both Laravel applications have the same version of the job class, and the job class is compatible with the version of Laravel and PHP on both servers.
  • The Horizon configurations on both servers are set up to monitor the correct queues.

If you've followed these steps and it's still not working, you may need to look into the following:

  • Check the Laravel logs for any errors related to queue jobs.
  • Use Redis monitoring tools or commands (MONITOR command in the Redis CLI) to see if the jobs are being pushed to the Redis server.
  • Ensure that the Horizon or queue worker on the second server is running and is not encountering any errors when processing jobs.

By following these steps, you should be able to dispatch jobs from one Laravel application to another using a shared Redis server.

Thumbtech's avatar

I would say that with Horizon in the mix this is not the way to go.

ryangurnick's avatar

So you are attempting to use job queues to dispatch jobs between servers?

Are you trying to add jobs to the queue on one server and then process them on a separate server?

Horizon might be able to help but this seem more architectural than horizon would care about and it does require Redis (which forge might handle for you).

UPDATE: I missed that you have two seperate horizon instances running on the two servers and have added some config. The config changes you added should be what is needed, however it will default to using one of the connections, so you may need to specify the connection when dispatching the job. Like @laryai mentioned above, but I think it got the wrong syntax. Please review laravel queue documentation here.

Thumbtech's avatar

@ryangurnick Thanks for replying. I'm really not very savvy with Redis, but thanks to Horizon, it seems to be the best solution for queue work. As a sort of database, I was assuming it should be fairly straightforward to use multiple connections to dispatch and/or listen (process) however one desired, but I really ran into a brick wall on this one and, after burning half a day, just switched gears.

In the end I just used spatie laravel remote https://github.com/spatie/laravel-remote to call a console command on the other machine which queues the job from there. The data gets passed through the command just fine. Feels like pounding nails with a sledgehammer, but it works fine.

ryangurnick's avatar

@Thumbtech That seems like another good solution. Glad you got it figured out!

The spatie team makes a ton of useful laravel packages.

Please or to participate in this conversation.