MEMCACHE.PCONNECT(3) 1 MEMCACHE.PCONNECT(3)Memcache::pconnect - Open memcached server persistent connection
SYNOPSIS
mixed Memcache::pconnect (string $host, [int $port], [int $timeout])
DESCRIPTION Memcache.pconnect(3) is similar to Memcache.connect(3) with the difference, that the connection it establishes is persistent. This connec-
tion is not closed after the end of script execution and by Memcache.close(3) function. Also you can use memcache_pconnect(3) function.
PARAMETERS
o $host
- Point to the host where memcached is listening for connections. This parameter may also specify other transports like
unix:///path/to/memcached.sock to use UNIX domain sockets, in this case $port must also be set to 0.
o $port
- Point to the port where memcached is listening for connections. Set this parameter to 0 when using UNIX domain sockets.
o $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.
RETURN VALUES
Returns a Memcache object or FALSE on failure.
EXAMPLES
Example #1
Memcache.pconnect(3) example
<?php
/* procedural API */
$memcache_obj = memcache_pconnect('memcache_host', 11211);
/* OO API */
$memcache_obj = new Memcache;
$memcache_obj->pconnect('memcache_host', 11211);
?>
SEE ALSO Memcache.connect(3).
PHP Documentation Group MEMCACHE.PCONNECT(3)
Check Out this Related Man Page
MEMCACHE.ADDSERVER(3) 1 MEMCACHE.ADDSERVER(3)Memcache::addServer - Add a memcached server to connection pool
SYNOPSIS
bool Memcache::addServer (string $host, [int $port = 11211], [bool $persistent], [int $weight], [int $timeout], [int $retry_inter-
val], [bool $status], [callable $failure_callback], [int $timeoutms])
DESCRIPTION Memcache.addServer(3) adds a server to the connection pool. You can also use the memcache_add_server(3) function.
When using this method (as opposed to Memcache.connect(3) and Memcache.pconnect(3)) the network connection is not established until actu-
ally needed. Thus there is no overhead in adding a large number of servers to the pool, even though they might not all be used.
Failover may occur at any stage in any of the methods, as long as other servers are available the request the user won't notice. Any kind
of socket or Memcached server level errors (except out-of-memory) may trigger the failover. Normal client errors such as adding an existing
key will not trigger a failover.
Note
This function has been added to Memcache version 2.0.0.
PARAMETERS
o $host
- Point to the host where memcached is listening for connections. This parameter may also specify other transports like
unix:///path/to/memcached.sock to use UNIX domain sockets, in this case $port must also be set to 0.
o $port
- Point to the port where memcached is listening for connections. Set this parameter to 0 when using UNIX domain sockets. Please
note: $port defaults to memcache.default_port if not specified. For this reason it is wise to specify the port explicitly in this
method call.
o $persistent
- Controls the use of a persistent connection. Default to TRUE.
o $weight
- Number of buckets to create for this server which in turn control its probability of it being selected. The probability is rela-
tive to the total weight of all servers.
o $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.
o $retry_interval
- Controls how often a failed server will be retried, the default value is 15 seconds. Setting this parameter to -1 disables auto-
matic retry. Neither this nor the $persistent parameter has any effect when the extension is loaded dynamically via dl(3). Each
failed connection struct has its own timeout and before it has expired the struct will be skipped when selecting backends to serve
a request. Once expired the connection will be successfully reconnected or marked as failed for another $retry_interval seconds.
The typical effect is that each web server child will retry the connection about every $retry_interval seconds when serving a
page.
o $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.
o $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.
o $timeoutms
-
NOTES
Warning
When the $port is unspecified, this method defaults to the value set of the PHP ini directive memcache.default_port If this value
was changed elsewhere in your application it might lead to unexpected results: for this reason it is wise to always specify the port
explicitly in this method call.
RETURN VALUES
Returns TRUE on success or FALSE on failure.
EXAMPLES
Example #1
Memcache.addServer(3) example
<?php
/* OO API */
$memcache = new Memcache;
$memcache->addServer('memcache_host', 11211);
$memcache->addServer('memcache_host2', 11211);
/* procedural API */
$memcache_obj = memcache_connect('memcache_host', 11211);
memcache_add_server($memcache_obj, 'memcache_host2', 11211);
?>
SEE ALSO Memcache.connect(3), Memcache.pconnect(3), Memcache.close(3), Memcache.setServerParams(3), Memcache.getServerStatus(3).
PHP Documentation Group MEMCACHE.ADDSERVER(3)