note 90320 added to function.base-convert

From: Date: Thu, 16 Apr 2009 08:58:18 +0000
Subject: note 90320 added to function.base-convert
Groups: php.notes 
Request: Send a blank email to php-notes+get-153379@lists.php.net to get a copy of this message
If you want to do sharding, at some point you will need to decide which shard to target. Here is a simple function to assign the data to a particular shard based on a key (usually identifier of the row) Here is a simple function to get the shard based on the key and the number of shards available function getShard($key,$nbShards) { $num = substr(base_convert(sha1($key), 16, 10),4,6); return $num%$nbShards; } ---- Server IP: 195.221.21.36 Probable Submitter: 82.150.248.28 ---- Manual Page -- http://www.php.net/manual/en/function.base-convert.php Edit -- https://master.php.net/note/edit/90320 Del: integrated -- https://master.php.net/note/delete/90320/integrated Del: useless -- https://master.php.net/note/delete/90320/useless Del: bad code -- https://master.php.net/note/delete/90320/bad+code Del: spam -- https://master.php.net/note/delete/90320/spam Del: non-english -- https://master.php.net/note/delete/90320/non-english Del: in docs -- https://master.php.net/note/delete/90320/in+docs Del: other reasons-- https://master.php.net/note/delete/90320 Reject -- https://master.php.net/note/reject/90320 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#153379) next »