Search code examples
phpsocketstcpredispredis

Predis persistant with PhpiredisStreamConnection


I am working on a Webservice and I'm using Predis as a redis library and I want the clients to be able to reuse the same TCP socket.

Currently , after running a load test on my service , I found that the number of socket in TIME_WAIT state increase fast on the server and at some point the connexion to Redis server gets refused.

According Redis documentation using PhpiredisStreamConnection with presistant option fixes the problem , but after adding this to my connect code , I m still facing the same issue. Any ideas?

Im using TCP connection as the redis instance are not on front servers.

<?php

include 'autoload.php';

$parameters = array(
'tcp://some.host01:6379?database=0&alias=master&persistent=1',
'tcp://some.host02:6379?database=0&alias=slave&persistent=1',
);

$options = array(   'replication' => true ,
'connections' =>  array('tcp'  => 'Predis\Connection\PhpiredisStreamConnection','unix' => 'Predis\Connection\PhpiredisStreamConnection') );

$predis = new Predis\Client($parameters, $options);

?>

Solution

  • As per the documents Predis works for persistent connections when php process are configured as persistent process . Look at the following for more details :

    https://github.com/joindin/joindin-web2/blob/master/vendor/predis-0.8/FAQ.md

    http://php-fpm.org/