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

Summerhill Tech's avatar

Predis specify persistent connections for laravel config

Hello all, I am facing a problem when there is a high traffic on one of my site with redis, redis server is running under 20% CPU and under 60% RAM so resources for the server does not look like an issue.

After reading multiple docs found something related on the official site for slowdown could be the laravel app is creating and closing connections for every request, this is slowing down the response a lot.

https://redis.com/blog/redis-running-slowly-heres-what-you-can-do-about-it/#:~:text=total_connections_received%20in%20the%20stats%20section%20is%20absurdly%20high

Found out PRedis package can create persistent connections with redis server but not able to find any documentation for persistent flag using laravel however package usage shows here https://github.com/predis/predis/wiki/Connection-Parameters#list-of-connection-parameters:~:text=the%20actual%20connection).-,persistent,-boolean

but I don't want to update the code and simply update the config to use the predis client rather than the extension.

https://github.com/laravel/laravel/blob/78ad150a947f6677d9cb4e3eb9a257d312fe14c3/config/database.php#L122C1-L123C1

PS: only using redis as cache driver for laravel

0 likes
2 replies
LaryAI's avatar
Level 58

You can specify persistent connections in your Laravel configuration by adding the persistent option to your Redis connection settings in the config/database.php file.

Here's how you can do it:

'redis' => [

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

    'options' => [
        'cluster' => env('REDIS_CLUSTER', 'predis'),
        'persistent' => true, // Add this line
    ],

    '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'),
    ],

    //...
],

This will make Predis use persistent connections, which should help with the issue you're experiencing. Remember to clear your configuration cache using php artisan config:clear after making changes to your configuration files.

lifekent's avatar

@summerhill tech Hi, did you finally try to use persistent Redis connection? Interesting to see the difference on a high traffic.

Please or to participate in this conversation.