Memcache::setServerParams

(PECL memcache >= 2.1.0)

Memcache::setServerParamsChanges server parameters and status at runtime

Description

Memcache::setServerParams(
    string $host,
    int $port = 11211,
    int $timeout = ?,
    int $retry_interval = false,
    bool $status = ?,
    callable $failure_callback = ?
): bool

Memcache::setServerParams() changes server parameters at runtime. You can also use the memcache_set_server_params() function.

Note:

This function has been added to Memcache version 2.1.0.

Parameters

host

Point to the host where memcached is listening for connections.

port

Point to the port where memcached is listening for connections.

timeout

Value in seconds which will be used for connecting to the daemon. Think twice before changing the default value of 1 second - you can lose all the advantages of caching if your connection is too slow.

retry_interval

Controls how often a failed server will be retried, the default value is 15 seconds. Setting this parameter to -1 disables automatic retry. Neither this nor the persistent parameter has any effect when the extension is loaded dynamically via dl().

status

Controls if the server should be flagged as online. Setting this parameter to false and retry_interval to -1 allows a failed server to be kept in the pool so as not to affect the key distribution algorithm. Requests for this server will then failover or fail immediately depending on the memcache.allow_failover setting. Default to true, meaning the server should be considered online.

failure_callback

Allows the user to specify a callback function to run upon encountering an error. The callback is run before failover is attempted. The function takes two parameters, the hostname and port of the failed server.

Return Values

Returns true on success or false on failure.

Examples

Example #1 Memcache::setServerParams() example

<?php

function _callback_memcache_failure($host$port) {
    print 
"memcache '$host:$port' failed";
}

/* OO API */

$memcache = new Memcache;

// Add the server in offline mode
$memcache->addServer('memcache_host'11211false11, -1false);

// Bring the server back online
$memcache->setServerParams('memcache_host'11211115true'_callback_memcache_failure');

/* procedural API */

$memcache_obj memcache_connect('memcache_host'11211);
memcache_set_server_params($memcache_obj'memcache_host'11211115true'_callback_memcache_failure');

?>

See Also

Here you can write a comment


Please enter at least 10 characters.
Loading... Please wait.
* Pflichtangabe
There are no comments available yet.

PHP cURL Tutorial: Using cURL to Make HTTP Requests

cURL is a powerful PHP extension that allows you to communicate with different servers using various protocols, including HTTP, HTTPS, FTP, and more. ...

TheMax

Autor : TheMax
Category: PHP-Tutorials

Midjourney Tutorial - Instructions for beginners

There is an informative video about Midjourney, the tool for creating digital images using artificial intelligence, entitled "Midjourney tutorial in German - instructions for beginners" ...

Mike94

Autor : Mike94
Category: KI Tutorials

Basics of views in MySQL

Views in a MySQL database offer the option of creating a virtual table based on the result of an SQL query. This virtual table can be queried like a normal table without changing the underlying data. ...

admin

Autor : admin
Category: mySQL-Tutorials

Publish a tutorial

Share your knowledge with other developers worldwide

Share your knowledge with other developers worldwide

You are a professional in your field and want to share your knowledge, then sign up now and share it with our PHP community

learn more

Publish a tutorial