unid 介绍
unid 是一个可以生成唯一ID的PHP扩展,此扩展基于 Twitter SNowflake 算法。有兴趣可以了解一下这个算法:
https://github.com/twitter/snowflake
功能列表:
// 1) Get the next unique ID. string unid_next_id(void); // 2) Change unique ID to time stamp. int unid_get_time(string id); // 3) Change unique ID to worker id. array unid_get_worker_id(string id);
示例:
<?PHP $id = unid_next_id(); echo $id; $time = unid_get_time($id); echo 'date time is: ' . date('Y-m-d H:i:s', $time); $worker_id = unid_get_worker_id(); echo 'worker id is: ' . $worker_id; ?>
$ cd ./unid $ PHPize $ ./configure $ make $ sudo make install
PHP.ini 配置项:
[unid] unid.datacenter = int unid.twepoch = uint64
unid 官网
https://github.com/liexusong/unid
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。