pconnect 命令/方法/函数


Connects to a Redis instance or reuse a connection already established with pconnect/popen.


The connection will not be closed on close or end of request until the php process ends. So be patient on to many open FD's (specially on redis server side) when using persistent connections on many servers connecting to one redis server.


Also more than one persistent connection can be made identified by either host + port + timeout or host + persistent_id or unix socket + timeout.


This feature is not available in threaded versions. pconnect and popen then working like their non persistent equivalents.



host: string. can be a host, or the path to a unix domain socket

port: int, optional

timeout: float, value in seconds (optional, default is 0 meaning unlimited)

persistent_id: string. identity for the requested persistent connection

Return Value

BOOL: TRUE on success, FALSE on error.


$redis->pconnect('', 6379);

$redis->pconnect(''); // port 6379 by default - same connection like before.

$redis->pconnect('', 6379, 2.5); // 2.5 sec timeout and would be another connection than the two before.

$redis->pconnect('', 6379, 2.5, 'x'); // x is sent as persistent_id and would be another connection the the three before.

$redis->pconnect('/tmp/redis.sock'); // unix domain socket - would be another connection than the four before.