note 80747 added to ref.memcache

From: Date: Wed, 30 Jan 2008 14:28:27 +0000
Subject: note 80747 added to ref.memcache
Groups: php.notes 
Request: Send a blank email to php-notes+get-135603@lists.php.net to get a copy of this message
Note that there is no way to have your own hashing mechanism, the best way to group a set of objects to a server is to manually select the server to use. I want to keep all objects for a certain user on the same server. user_54_description user_54_info user_54_comments user_54_etc . . If I have all these objects on the same server I can get all data with only one call to memcache -> get (get_multi), so this improves performance a lot. The way I do this is by hashing the User/Object id to to the number of servers. <?php $memcache_hosts = array ( '192.168.1.1', '192.168.1.2', '192.168.1.3', '192.168.1.4', '192.168.1.5', ); $server = $id % count($memcache_hosts); $memcache = new Memcache; $memcache->connect($memcache_hosts[$server], 11211); //get or set your objects here ?> You can leave other objects that you don't want to group to memcache extension to hash and select the appropiate server. ---- Server IP: 69.147.83.197 Probable Submitter: 86.121.48.100 ---- Manual Page -- http://www.php.net/manual/en/ref.memcache.php Edit -- https://master.php.net/note/edit/80747 Del: integrated -- https://master.php.net/note/delete/80747/integrated Del: useless -- https://master.php.net/note/delete/80747/useless Del: bad code -- https://master.php.net/note/delete/80747/bad+code Del: spam -- https://master.php.net/note/delete/80747/spam Del: non-english -- https://master.php.net/note/delete/80747/non-english Del: in docs -- https://master.php.net/note/delete/80747/in+docs Del: other reasons-- https://master.php.net/note/delete/80747 Reject -- https://master.php.net/note/reject/80747 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#135603) next »