Is it possible for the PHP function uniqid() to generate the same name twice?Get the solution ↓↓↓
I have been using the function uniqid(), but I'm thinking, is it possible for the PHP function
uniqid() to generate the same random name twice?
The answer that I see everywhere is no, but why? why isn't it possible to generate a name that was generated before by kind of mistake. I mean it probably could generate a name that was generated before, even if it was set to true like this =>
uniqid('', true), it may generate the same name by coincidence?
Warning This function does not guarantee uniqueness of return value. Since most systems adjust system clock by NTP or like, system time is changed constantly. Therefore, it is possible that this function does not return unique ID for the process/thread. Use more_entropy to increase likelihood of uniqueness.
My answer it is possible, but not practical.
Much like the no two snowflakes are alike statement, it might happen, but the odds of anyone noticing are seriously small?
When you look at the odds, we are talking about being struck by lightning while standing under a metal shelter on a sunny day type of odds.
If you want to do the math feel free.
Unless you are dealing with the "rather extreme edge-case" of two-or-more threads possibly calling this function simultaneously within the same microsecond .... I would say that "your fears are comfortably unfounded."
Share solution ↓
Link To Answer People are also looking for solutions of the problem: a non-numeric value encountered in
Didn't find the answer?
Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.
Find the answer in similar questions on our website.
Write quick answer
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.