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

raslin's avatar

configure multiple memcached servers?

Hey all, i just started exploring lumen for some microservices in our company.

i'm trying to configure multiple memcached hosts. but in the .env file seems like there is a place just for one (MEMCACHED_HOST)

how can i set a list of memcache servers?

0 likes
4 replies
raslin's avatar

Thats the nature of memcached, to be distributed, i need more than one, i saw many examples of that for laravel, Cant figure it out in lumen

igorblumberg's avatar
Level 7

@raslin You can copy the cache config file from /vendor/larave/lumen-framework/config/cache.php to /config/cache.php

In that file add the servers you need, like this:

'memcached' => [
            'driver'  => 'memcached',
            'servers' => [
                [
                    'host' => env('MEMCACHED_HOST', '127.0.0.1'), 'port' => env('MEMCACHED_PORT', 11211), 'weight' => 50
                ],                
        [   
                    'host' => env('MEMCACHED_HOST1', '127.0.0.1'), 'port' => env('MEMCACHED_PORT', 11211), 'weight' => 50
                ]
            ],
        ],

And add, on the /bootstrap/app.php the following:

$app->configure('cache');
1 like
nicat's avatar

in my case this example doesn't write cache parallel in both memached server.

Please or to participate in this conversation.