This extension provides a simple class for consistent hashing.
This code is maintained by Simon Effenberg. You can send comments, patches, questions here on github.
phpize ./configure make && make install
or as debian package
dpkg-buildpackage
This extension exports a single class, ConsistentHashing
.
php-consistenthashing throws an Exception
if invalid parameters will be passed to the functions
Creates a ConsistentHashing object
$ch = new ConsistentHashing();
adds a target to the internal ring structure where the weight
parameter
determines if the target should be found more often
target: string
weight: int (optional, default is 1 and should be 1 or greater)
$ch->addTarget('myhost1'); $ch->addTarget('myhost2', 2);
Get the target (added with addTarget
) the specified key should be on.
key: string
String or NULL: If no target exists (because addTarget wasn't called), NULL
is returned. Otherwise, the target related to this key is returned.
$ch->getTarget('key');