jump2 / yii2-snowflake
yii2 snowflake extension
1.0.3
2018-06-26 16:00 UTC
Requires
- php: >=5.4.0
- ext-swoole: *
- yiisoft/yii2: ~2.0.0
This package is auto-updated.
Last update: 2025-01-07 05:32:58 UTC
README
yii2 snowflake extension, your have to install swoole of php extension
Installation
The preferred way to install this extension is through composer.
Either run
composer require --prefer-dist jump2/yii2-snowflake "*"
or add
"jump2/yii2-snowflake": "*"
to the require section of your composer.json
file.
Configuration
First of all , you have to configure the Server class in your console application configuration:
'snowflakeServer' => [ 'class' => 'Snowflake\Server', 'host' => '0.0.0.0', 'port' => 5599, 'workerId' => 1, 'datacenterId' => 1 ],
and create console controller like the file below the example directory, then run it for start the snowflake server
Next, you have to configure the Client class in your application configuration:
'snowflakeClient' => [ 'class' => 'Snowflake\Client', 'host' => '0.0.0.0', 'port' => 5599 ],
Use below code to generate id
<?php echo \Yii::$app->snowflakeClient->nextId(); ?>