CakeFest 2024: The Official CakePHP Conference

Memcache::getServerStatus

(PECL memcache >= 2.1.0)

Memcache::getServerStatusサーバーの状態を返す

説明

Memcache::getServerStatus(string $host, int $port = 11211): int

Memcache::getServerStatus() は、サーバーがオンライン/オフラインのどちらであるかを返します。 memcache_get_server_status() 関数を使用することも可能です。

注意:

この関数は、Memcache バージョン 2.1.0 で追加されました。

パラメータ

host

memcached が接続を待ち受けるホストを指定します。

port

memcached が接続を待ち受けるポートを指定します。

戻り値

サーバーの状態を返します。サーバーに接続できなかった場合に 0、 それ以外の場合にはゼロ以外の値を返します。

例1 Memcache::getServerStatus() の例

<?php

/* オブジェクト指向の API */
$memcache = new Memcache;
$memcache->addServer('memcache_host', 11211);
echo
$memcache->getServerStatus('memcache_host', 11211);

/* 手続き型の API */
$memcache = memcache_connect('memcache_host', 11211);
echo
memcache_get_server_status($memcache, 'memcache_host', 11211);

?>

参考

add a note

User Contributed Notes 2 notes

up
4
geoffrey dot hoffman at gmail dot com
13 years ago
Beware... this method does not actually attempt to connect to the server and port you specify! It is not a health check to tell whether memcached is actually running or not!

It merely returns the server status from the pool, which defaults to TRUE when using addServer( ) with only required arguments.

Try it - stop your memcached and run the sample code above - it will output 1.
up
0
tom at all dash community dot de
12 years ago
Note: the result of the function is cached. The cached is not automatically refreshed.

Call MemCache::getExtendedStats() to force a cache-update.
To Top