note 110003 added to memcached.addserver

From: Date: Mon, 10 Sep 2012 18:55:10 +0000
Subject: note 110003 added to memcached.addserver
Groups: php.notes 
Request: Send a blank email to php-notes+get-190613@lists.php.net to get a copy of this message
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: 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); } } ---- Server IP: 201.216.232.240 Probable Submitter: 190.244.1.22 (proxied: 190.244.1.22) ---- Manual Page -- http://www.php.net/manual/en/memcached.addserver.php Edit -- https://master.php.net/note/edit/110003 Del: integrated -- https://master.php.net/note/delete/110003/integrated Del: useless -- https://master.php.net/note/delete/110003/useless Del: bad code -- https://master.php.net/note/delete/110003/bad+code Del: spam -- https://master.php.net/note/delete/110003/spam Del: non-english -- https://master.php.net/note/delete/110003/non-english Del: in docs -- https://master.php.net/note/delete/110003/in+docs Del: other reasons-- https://master.php.net/note/delete/110003 Reject -- https://master.php.net/note/reject/110003 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#190613) next »