How to close or reset a pconnect() connection when using PHPRedis and PHP-FPM?

in phpredis 4.3.0, close() can close connection created by pconnect(). if you use redis method after close(), a new persistent connection will be auto created.


Are you calling pconnect with a timeout? Assuming the connection is closed each time the timeout is exceeded, you could re-resolve the master before calling pconnect again with a different address.

If you are running a Redis cluster, PHPRedis has a cluster mode with timeout behaviour that's specific to this setup with support for 'MOVED' response: https://github.com/phpredis/phpredis/blob/develop/cluster.markdown#timeout


Persistent streams are provided by PHP internals, it is unwritten law that anything that exposes a way to create a persistent stream should also provide a way to destroy it.

PHP Redis breaks that law, there is simply no way for you to destroy that persistent stream from userland.

The course of action should be to PR an implementation of the required method.

Here's a patch against the PHP7 branch which implements Redis::pclose: https://gist.github.com/krakjoe/326eadc61bea38fdd6e6

Note that, the code for pdisconnect is based off of the existing disconnect, both of these functions look strange to me and aren't honest about their return value. I assume there are some tests or code somewhere relying on that strangeness so haven't attempted to fix it.

Any PR should mention that these functions look odd, and PHP7 is the perfect time to break stuff.