AtomPHP唯一ID生成擴(kuò)展
使用Twitter的 Snowflake算法,有興趣可以了解一下這個(gè)算法: https://github.com/twitter/snowflake
php.ini的配置項(xiàng):
[ukey] ukey.datacenter = integer ukey.worker = integer ukey.twepoch = uint64
-
datacenter配置項(xiàng)是一個(gè)整數(shù), 用于設(shè)置數(shù)據(jù)中心;
-
worker配置項(xiàng)是一個(gè)整數(shù), 用于設(shè)置數(shù)據(jù)中心的機(jī)器序號(hào);
-
twepoch配置項(xiàng)是一個(gè)64位的整數(shù), 用于設(shè)置時(shí)間戳基數(shù), 此值越大, 生成的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評(píng)論
圖片
表情
