略微加速

PHP官方手册 - 互联网笔记

PHP - Manual: Memcache::pconnect

2024-04-17

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.

范例

示例 #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);

?>

参见

add a noteadd a note

User Contributed Notes 2 notes

up
1
john.royer [at] gmail.com
3 years ago
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
up
-26
office at cws-trummer dot biz
13 years ago
use persistent connection if you have problems with system process 0 WAIT_TIME

官方地址:https://www.php.net/manual/en/memcache.pconnect.php

北京半月雨文化科技有限公司.版权所有 京ICP备12026184号-3