I need to get time based unique id which would only consist of numbers, i was thinking to simply use something like this:
str_replace(".", "", microtime(true))
I would use this id for many things, for example comments posting, and i'm expecting quite high traffic so i would like to know how high are the chances of collision with microtime
function?
And perhaps there is a better way to get numerical unique id? Just remember that it has to based on time so sorting could be done.
you can use this to get uniqid but is not numberic:
$id = uniqid(); //58aea16085f6b
use this to convert it to only numbers:
$id = hexdec( uniqid() ); //1560112880181100
if it's too long use this but maybe get negetive numbers:
$id = crc32( uniqid() ); //-1551585806
if you just need posetive numbers you can do it:
$id = abs( crc32( uniqid() ) ); //1551585806
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With