[php-src] PR #19202: Refactor basic time usages
| From: | marc-mabe | Date: | Mon, 21 Jul 2025 13:55:33 +0000 |
| Subject: | [php-src] PR #19202: Refactor basic time usages | ||
| Groups: | php.git-pulls | ||
| Request: | Send a blank email to git-pulls+get-32548@lists.php.net to get a copy of this message | ||
Pull Request: https://github.com/php/php-src/pull/19202
Author: marc-mabe
This refactors the internal usages of the current time.
* Introduced
php_time.h to be used instead of system time.h
* Added php_realtime_get, php_realtime_spec and
php_realtime_res as a wrapper around timespec_get]res},
clock_get[time|res], gettimeofday and time using the realtime
clock
* Added php_monotime_get, php_monotime_spec and
php_monotime_res as a wrapper around timespec_get]res},
clock_get[time|res] using the monotonic clock
* Added helper macros for working with timeval and timespec
* Replace direct usages of the system time API with php_*
* migrate to timespec for current time but keep timeval for timeouts
As a result:
* The code is better readable because system differences are encapsulated
* php_realtime_get will not fail as it falls back timespec_get ->
clock_gettime -> gettimeofday -> time and
time will never fail
* php_realtime_get will be available for sure because of the same
* Y2038 problem of WIN64 due to long of timeval.tv_sec should be avoided
* Increased time resolution of microtime() / gettimeofday(true) without BC
break
* uniqid refactored a bit to not wait for the next time but increments if the current
time is less or equal to the previous call. This should be faster and resolve a theoretical issue if
the real time got modified in between (ntp)
Even thought gettimeofday may not be available it wasn't checked everywhere before
and compiling would have been failed already before. Availability should now be checked but as it
falls back and it must have been available before I removed the conditions around
microtime, gettimeofday and uniqid
PS: It's not fully refactored yet but a general pre-review would be welcome.