Skip to content

Refactor basic time usages #19202

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

marc-mabe
Copy link
Contributor

@marc-mabe marc-mabe commented Jul 21, 2025

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 and php_realtime_spec as a wrapper around clock_gettime, timespec_get, gettimeofday and time using the realtime clock
  • Added php_monotime_fallback either pointing to zend_hrtime or wrapping php_realtime_spec
    • this can be used for time measurements (like timeout handling) where a monotonic timer is preferable but a fallback to real/wall-time without high resolution requirement is still better than nothing
  • 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 be available for sure because it falls back clock_gettime -> timespec_get -> gettimeofday -> time
  • Y2038 problem of WIN64 due to long of timeval.tv_sec should be fixed time() and friends have Y2038 problem on 64 Windows #17856
  • 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 if missing. 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.

@marc-mabe
Copy link
Contributor Author

This is related to #19210

@marc-mabe marc-mabe force-pushed the current_time_wrapper branch from 8c044c8 to 3d9c05a Compare July 23, 2025 16:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

time() and friends have Y2038 problem on 64 Windows
1 participant
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy