Memcache::pconnect

(PECL memcache >= 0.4.0)

Memcache::pconnect打开一个到服务器的持久化连接

说明

Memcache::pconnect ( string $host [, int $port [, int $timeout ]] ) : mixed

Memcache::pconnect()Memcache::connect()非常类似,不同点在于这里建立的连接是持久化的。 这个连接不会在脚本执行结束后或者Memcache::close()被调用后关闭。 同样你也可以使用函数memcache_pconnect()

参数

host

服务端监听的主机地址。这个参数还可以指定为其他传输方式比如unix:///path/to/memcached.sock 来使用Unix域套接字,使用这种方式port参数必须设置为0

port

服务端监听的端口号。使用Unix域套接字的时候需要将这个参数设置为0

timeout

连接持续(超时)时间,单位秒。默认值1秒,修改此值之前请三思,过长的连接持续时间可能会导致失去所有的缓存优势。

返回值

返回一个 Memcache 对象 或者在失败时返回 FALSE.

范例

Example #1 Memcache::pconnect()示例

<?php

/* procedural API */
$memcache_obj memcache_pconnect('memcache_host'11211);

/* OO API */

$memcache_obj = new Memcache;
$memcache_obj->pconnect('memcache_host'11211);

?>

参见

User Contributed Notes

john.royer [at] gmail.com 15-Oct-2018 03:47
pconnect() put error message to stderr if connection failed. This behavior may cause unexpected output.
use '@' infrom of `pconnect()` to avoid it.

<?php

$cache
= new Memcache();
$stat = @$cache->pconnect('localhost', 11211);

if (
false === $stat) {
   
// connect failed
}
// connect success
office at cws-trummer dot biz 20-Mar-2009 02:17
use persistent connection if you have problems with system process 0 WAIT_TIME