I couldn't find the actual function's code as I am interested in how it creates the id, e.g. where it gets the time from.
4 Answers
If you're still interested in the source, it's in the public git repository: https://github.com/php/php-src/blob/master/ext/standard/uniqid.c
gettimeofday((struct timeval *) &tv, (struct timezone *) NULL);
sec = (int) tv.tv_sec;
usec = (int) (tv.tv_usec % 0x100000);
/* The max value usec can have is 0xF423F, so we use only five hex
* digits for usecs.
*/
if (more_entropy) {
spprintf(&uniqid, 0, "%s%08x%05x%.8F", prefix, sec, usec, php_combined_lcg(TSRMLS_C) * 10);
} else {
spprintf(&uniqid, 0, "%s%08x%05x", prefix, sec, usec);
}
RETURN_STRING(uniqid, 0);

- 4,438
- 1
- 20
- 40
Which function? I don't believe there's a unique_id()
function in PHP. The code for uniqid()
is in ext/standard/uniqid.c.
You can search for this kind of thing on Github by narrowing down the repository. For example, searching for repo:php/php-src uniqid will find references to uniqid in the php repo.
There's an example of this, and other Github search syntax, in the answer to this earlier question.

- 1
- 1

- 37,886
- 9
- 99
- 128
You'll find the source code for uniqid() in https://github.com/php/php-src/blob/master/ext/standard/uniqid.c

- 209,507
- 32
- 346
- 385
This might help from the manual: http://php.net/manual/en/function.uniqid.php
It explains the uniqueness is taken from the time in microseconds.

- 15,747
- 13
- 83
- 165
-
It doesn't give me the actual code though, I am looking to see how that function is made – user1166981 Jan 12 '13 at 00:36