函數(shù)名稱:Memcache::setServerParams()
函數(shù)描述:設(shè)置Memcache服務(wù)器參數(shù)
適用版本:PHP 5 >= 5.2.0, PECL memcache >= 2.0.0
語(yǔ)法:bool Memcache::setServerParams(string $host [, int $port = 11211 [, int $timeout [, int $retry_interval [, bool $status [, callable $failure_callback [, int $timeoutms ]]]]]])
參數(shù):
- $host:Memcache服務(wù)器的主機(jī)名或IP地址。
- $port:可選參數(shù),Memcache服務(wù)器的端口號(hào),默認(rèn)為11211。
- $timeout:可選參數(shù),與服務(wù)器建立連接的超時(shí)時(shí)間(以秒為單位),默認(rèn)為1秒。
- $retry_interval:可選參數(shù),重試連接的間隔時(shí)間(以秒為單位),默認(rèn)為15秒。
- $status:可選參數(shù),是否啟用服務(wù)器,默認(rèn)為true。
- $failure_callback:可選參數(shù),當(dāng)服務(wù)器連接失敗時(shí)的回調(diào)函數(shù)。
- $timeoutms:可選參數(shù),與服務(wù)器建立連接的超時(shí)時(shí)間(以毫秒為單位),默認(rèn)為0。
返回值:成功時(shí)返回true,失敗時(shí)返回false。
示例:
$memcache = new Memcache;
$memcache->addServer('localhost', 11211);
$host = 'localhost';
$port = 11211;
$timeout = 1;
$retry_interval = 15;
$status = true;
$failure_callback = null;
$timeoutms = 0;
$result = $memcache->setServerParams($host, $port, $timeout, $retry_interval, $status, $failure_callback, $timeoutms);
if ($result) {
echo "Memcache服務(wù)器參數(shù)設(shè)置成功!";
} else {
echo "Memcache服務(wù)器參數(shù)設(shè)置失??!";
}
該示例演示了如何使用Memcache::setServerParams()函數(shù)來(lái)設(shè)置Memcache服務(wù)器的參數(shù)。首先,創(chuàng)建一個(gè)Memcache對(duì)象并添加服務(wù)器。然后,通過(guò)傳遞相應(yīng)的參數(shù)調(diào)用setServerParams()函數(shù)來(lái)設(shè)置服務(wù)器參數(shù)。最后,根據(jù)返回值判斷設(shè)置是否成功,并輸出相應(yīng)的消息。