PHP code example of delz / snowflake-php-sdk

1. Go to this page and download the library: Download delz/snowflake-php-sdk 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/ */

    

delz / snowflake-php-sdk example snippets





use Delz\Snowflake\SnowflakeClient;
use Delz\Snowflake\SnowflakeRequest;
use Grpc\ChannelCredentials;


//利用composer自动加载,具体路径请修改
tServiceId(0);
//设置返回id格式为int64
$request->setFormat('int64');
//二进制
//$request->setFormat('base2');
//36进制 26字母+10个数字
//$request->setFormat('base36');
//base32
//$request->setFormat('base32');
//base58
//$request->setFormat('base58');
//base64
//$request->setFormat('base64');
list($reply,$status) = $client->Gen($request)->wait();

if($status->code != 0) {
    echo "服务器故障";
} else {
    //获取id
    echo $reply->getId();
}