Twitter distributed ID generating Algorithm SnowFlake PHP implementation version.
Pure PHP can not be achieved SnowFlake algorithm,because version of thread-safe(requires tid)and non-thread-safe(requires pid)can not generate same the format id(The only tid of this project system, so don't worried about pid conflict of multiple processes). And PHP as scripting language can not maintain sequence, sequence will be initialized again when the script is finished. In case of high concurrency pure PHP Implemented version of Snowflate algorithm does not have any effect. So was born this project, below is the different of Thread-safe version and Non-thread-safe version.
0 2 15 20 28 32
---+----------------+--------------+----+----------+
00 |timestamp(ms) | service_no |pid | sequence |
---+----------------+--------------+----+----------+
0 2 15 20 28 32
---+----------------+--------------+----+----------+
00 |timestamp(ms) | service_no |tid | sequence |
---+----------------+--------------+----+----------+
phpize
./configure --with-php-config=/you/phppath/php-config
make
make install
Attention: Interval of $service_no in the range of 0-99999. Beyond that scope, PHP will report a fatal mistake.
$service_no = 999;
for ($i=0; $i < 10; $i++) {
echo PhpSnowFlake::nextId($service_no)."\n";
}
/*
00146523488416500999000634280001
00146523488416500999000634280002
00146523488416500999000634280003
00146523488416500999000634280004
00146523488416500999000634280005
00146523488416600999000634280001
00146523488416600999000634280002
00146523488416600999000634280003
00146523488416600999000634280004
00146523488416600999000634280005
*/
Copyright (c) 2016 by Towers released under MIT License.
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。
1. 开源生态
2. 协作、人、软件
3. 评估模型