'How safe is Php PDO function: lastInsertId?

I have little confusion about the Php PDO function: lastInsertID. If I understand correctly, it returns the last auto-incremental id that was inserted in the database.

I usually use this function when I execute a query that inserts a user in my database when I am creating the functionality of registering a user.

My question is that say I have a hundred people registering on my site at one point for example. And may be one user hit the 'Register' button a millisecond after another user. Then is there a chance that this function lastInsertId will return the id of another user that register just momentarily earlier?

May be what I am trying to ask is does the server handle one request at a time and go through a php file one at a time?

Please let me know about this.

Thank you.



Solution 1:[1]

Perfectly safe. There is no race condition. It only returns the last inserted Id from the pdo object that made the insert.

Solution 2:[2]

It is safe - it guarantees to return you a value from the current connection.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 eidsonator
Solution 2 zerkms