note 90320 modified in function.base-convert by danbrown

From: Date: Thu, 16 Apr 2009 12:59:30 +0000
Subject: note 90320 modified in function.base-convert by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-153383@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 <?php function getShard($key,$nbShards) { $num = substr(base_convert(sha1($key), 16, 10),4,6); return $num%$nbShards; } ?> --was-- 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; } http://php.net/manual/en/function.base-convert.php

« previous php.notes (#153383) next »