查詢

Memcached::isPersistent()函式—用法及示例

「 檢查當前Memcached連線是否是持久連線 」


函式名稱:Memcached::isPersistent()

函式描述:該函式用於檢查當前Memcached連線是否是持久連線。

函式用法:bool Memcached::isPersistent ( void )

引數說明:該函式不接受任何引數。

返回值:如果當前連線是持久連線,則返回true;否則返回false。

示例程式碼:

// 建立一個新的Memcached物件
$memcached = new Memcached();

// 新增一個伺服器到連線池中
$memcached->addServer('localhost', 11211);

// 檢查連線是否是持久連線
$isPersistent = $memcached->isPersistent();

// 列印結果
if ($isPersistent) {
    echo "連線是持久連線";
} else {
    echo "連線不是持久連線";
}

在上面的示例中,我們首先建立了一個新的Memcached物件,並新增了一個Memcached伺服器到連線池中。然後,我們使用isPersistent()函式來檢查當前連線是否是持久連線。最後,根據返回值列印出相應的結果。

請注意,isPersistent()函式只能在Memcached物件已經連線到伺服器之後呼叫。如果在連線之前呼叫該函式,會丟擲一個MemcachedException異常。

補充糾錯
熱門PHP函式
分享連結