Voting

: one minus one?
(Example: nine)

The Note You're Voting On

mbarriolinares at gmail dot com
12 years ago
Important to not call ->addServers() every run -- only call it if no servers exist (check getServerList() ); otherwise, since addServers() does not check for dups, it will let you add the same server again and again and again, resultings in hundreds if not thousands of connections to the MC daemon. Specially when using FastCGI.

Example:

<?php
class Cache {
private
$id;
private
$obj;

function
__construct($id){
$this->id = $id;
$this->obj = new Memcached($id);
}

public function
connect($host , $port){
$servers = $this->obj->getServerList();
if(
is_array($servers)) {
foreach (
$servers as $server)
if(
$server['host'] == $host and $server['port'] == $port)
return
true;
}
return
$this->obj->addServer($host , $port);
}

}
?>

<< Back to user notes page

To Top