Skip to content

Instantly share code, notes, and snippets.

@iamcal
Created January 24, 2012 00:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save iamcal/1666684 to your computer and use it in GitHub Desktop.
Save iamcal/1666684 to your computer and use it in GitHub Desktop.
function consistent_hash($path, $servers){
$hash = hexdec(substr(md5($path), 0, 5));
return $cache[$hash % count($servers)];
}
$server = consistent_hash($path_to_asset, array('cache1', 'cache2'));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment