note 93536 added to memcached.construct

From: Date: Tue, 15 Sep 2009 09:43:35 +0000
Subject: note 93536 added to memcached.construct
Groups: php.notes 
Request: Send a blank email to php-notes+get-160572@lists.php.net to get a copy of this message
When using persistent connections, it is important to not re-add servers. This is what you do not want to do: <?php $mc = new Memcached('mc'); $mc->setOption(Memcached::OPT_LIBKETAMA_COMPATIBLE, true); $mc->addServers(array( array('mc1.example.com',11211), array('mc2.example.com',11211), )); ?> Every time the page is loaded those servers will be appended to the list resulting in many simultaneous open connections to the same server. The addServer/addServers functions to not check for existing references to the specified servers. A better approach is something like: <?php $mc = new Memcached('mc'); $mc->setOption(Memcached::OPT_LIBKETAMA_COMPATIBLE, true); if (!count($mc->getServerList())) { $mc->addServers(array( array('mc1.example.com',11211), array('mc2.example.com',11211), )); } ?> ---- Server IP: 209.41.74.194 Probable Submitter: 64.81.234.124 ---- Manual Page -- http://www.php.net/manual/en/memcached.construct.php Edit -- https://master.php.net/note/edit/93536 Del: integrated -- https://master.php.net/note/delete/93536/integrated Del: useless -- https://master.php.net/note/delete/93536/useless Del: bad code -- https://master.php.net/note/delete/93536/bad+code Del: spam -- https://master.php.net/note/delete/93536/spam Del: non-english -- https://master.php.net/note/delete/93536/non-english Del: in docs -- https://master.php.net/note/delete/93536/in+docs Del: other reasons-- https://master.php.net/note/delete/93536 Reject -- https://master.php.net/note/reject/93536 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#160572) next »