PHP code example of yiranzai / hash-dht

1. Go to this page and download the library: Download yiranzai/hash-dht library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

yiranzai / hash-dht example snippets


$hash = new Yiranzai\Dht\Hash();
$hash->addEntityNode('db_server_one')->addEntityNode('db_server_two');
$dbServer =  $hash->getLocation('key_one');
Yiranzai\Dht\Hash::cache($hash->toArray());
$hash = new Yiranzai\Dht\Hash(Yiranzai\Dht\Hash::getCache());
$dbServer =  $hash->getLocation('key_one');

$hash = new Yiranzai\Dht\Hash();
$hash->deleteEntityNode('db_server_one');

$hash = new Yiranzai\Dht\Hash();
$hash->algo('sha256');

//or

$hash = new Yiranzai\Dht\Hash(['algo' => YOUR_ALGO]);

$hash = new Yiranzai\Dht\Hash();
$hash->path(YOUR_PATH);

//or

$hash = new Yiranzai\Dht\Hash(['cachePath' => YOUR_PATH]);