• 首页
  • vue
  • TypeScript
  • JavaScript
  • scss
  • css3
  • html5
  • php
  • MySQL
  • redis
  • jQuery
  • Memcache::pconnect()

    (PECL memcache >= 0.4.0)

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

    说明

    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);
    ?>
    

    参见

    • Memcache::connect() 打开一个memcached服务端连接
    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
    use persistent connection if you have problems with system process 0 WAIT_TIME