Search code examples
phpunique-idmicrotimenanotime

Finding Nano Time in Windows using PHP


I would like to create a unique id in php.I used uniqid() but microtime is not helping because the function is inside a loop and a set of consecutive results are exactly the same!! So i am wondering if i can use nano time.In linux it possible using system() function. Is there any such ways in windows through which I can get nano time in PHP?


Solution

  • my idea is to add rand() as a prefix like so:

    md5(uniqid(rand(), true));
    

    the md5() is just a wrapper to make them pretty, you can remove it or format the results in other way depending on your need.