The behavior of Memcache::connect() is to always reinitialize the pool from scratch regardless of any previous calls to addServer().
E.g.
$mmc = new Memcache()
$mmc->addServer('node1', 11211);
$mmc->addServer('node2', 11211);
$mmc->addServer('node3', 11211);
$mmc->connect('node1', 11211);
The last connect() call clears out the pool and then add and connect node1:11211 making it the only server.
If you want a pool of memcache servers, do not use the connect() function.
If you only want a single memcache server then there is no need to use the addServer() function.
Memcache::connect
(PECL memcache:0.2-2.1.2)
Memcache::connect — memcached サーバへの接続をオープンする
説明
Memcache::connect() は、memcached サーバへの接続を 確立します。 Memcache::connect() を使用してオープンされた接続は、 スクリプトの実行終了時に自動的に閉じられます。 Memcache::close() を使用して閉じることも可能です。 memcache_connect() 関数を使用することも可能です。
パラメータ
- host
-
memcached が接続を待ち受けるホストを指定します。 このパラメータには別のトランスポート層を指定することもできます。たとえば unix:///path/to/memcached.sock のようにすると Unix ドメインソケットを使用できます。この場合、 port は 0 を指定しなければなりません。
- port
-
memcached が接続を待ち受けるポートを指定します。 Unix ドメインソケットを使用する場合は、このパラメータを 0 とします。
- timeout
-
デーモンへの接続の際に使用する値 (秒単位) です。 デフォルト値を 1 秒でも変更する前には十分注意してください。 接続が遅くなってしまうと、 キャッシュ処理のメリットが なくなってしまいます。
返り値
成功した場合に TRUE を、失敗した場合に FALSE を返します。
例
例1 Memcache::connect() の例
<?php
/* 手続き型の API */
$memcache_obj = memcache_connect('memcache_host', 11211);
/* オブジェクト指向の API */
$memcache = new Memcache;
$memcache->connect('memcache_host', 11211);
?>
Memcache::connect
05-Sep-2006 05:39
