微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

Atom PHP唯一ID生成扩展

程序名称:Atom

授权协议: GPL

操作系统: 跨平台

开发语言: PHP

Atom 介绍


使用Twitter的 SNowflake算法,有兴趣可以了解一下这个算法: https://github.com/twitter/snowflake

PHP.ini的配置项:

[ukey]
ukey.datacenter = integer
ukey.worker = integer
ukey.twepoch = uint64
  • datacenter配置项是一个整数, 用于设置数据中心;

  • worker配置项是一个整数, 用于设置数据中心的机器序号;

  • twepoch配置项是一个64位的整数, 用于设置时间戳基数, 此值越大, 生成的ID越小;

Atom

Based on the Twitter SNowflake algorithm

PHP unique ID generator

functions list:

  • 1) string atom_next_id (void);
    Get the next unique ID.

  • 2) array atom_explain (string ID);
    Change unique ID to array includes: timestamp, datacenter id and worker id.

example:

<?PHP
$id = atom_next_id();
echo $id;

$info = atom_explain($id);
echo date('Y-m-d H:i:s', $info['timestamp']);
?>

install:

$  cd ./atom
$  PHPize
$  ./configure
$  make
$  sudo make install

PHP.ini configure entries:

[atom]
atom.datacenter = integer
atom.worker = intger
atom.twepoch = uint64

Atom 官网

https://github.com/liexusong/atom

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐