[php-src] PR #19264: More unique uniqid (no BC)
| From: | marc-mabe | Date: | Sun, 27 Jul 2025 12:15:07 +0000 |
| Subject: | [php-src] PR #19264: More unique uniqid (no BC) | ||
| Groups: | php.git-pulls | ||
| Request: | Send a blank email to git-pulls+get-32629@lists.php.net to get a copy of this message | ||
Pull Request: https://github.com/php/php-src/pull/19264
Author: marc-mabe
Currently
uniqid waits until the current microsecond has been changed until the
previous call.
This PR changes this this logic instead of waiting until the current microsecond changes, it simply
increments in case the current time is <= the previous.
This makes uniqid unaffected by time changes (like ntp) and also it's faster (if
called very often) due to less system calls.
A simple benchmark:
BEFORE: 100911477ns
AFTER: 57341969ns
```php
uniqid(); // warmup
$start = hrtime(true);
for ($i = 0; $i < 100000; ++$i) {
uniqid();
}
echo (hrtime(true) - $start) . "ns\n";
```