Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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

Open
marc-mabe wants to merge 6 commits into php:master
base: master
Choose a base branch
Loading
from marc-mabe:current_time_wrapper

Conversation

Copy link
Contributor

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

This refactors the internal usages of the current time.

  • Introduced zend_time.h to be used instead of system time.h
  • Added zend_realtime_spec as a wrapper around clock_gettime, timespec_get, gettimeofday and time using the real/wall clock providing a timespec with up to nanosecond resolution
  • Added zend_realtime_get as a macro wrapper for time(NULL)
  • Added zend_monotime_fallback either pointing to zend_hrtime or wrapping zend_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 zend_realtime_* / zend_monotime_fallback
  • migrate to timespec for current time but keep timeval as it's needed for file/streams

As a result:

  • The code is better readable because system differences are encapsulated
  • zend_realtime_get / zend_realtime_spec and zend_monotime_fallback 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

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

zbenc reacted with rocket emoji
@marc-mabe marc-mabe force-pushed the current_time_wrapper branch 2 times, most recently from db6170e to 88052ab Compare July 25, 2025 07:37
@marc-mabe marc-mabe marked this pull request as ready for review July 25, 2025 08:12
@marc-mabe marc-mabe force-pushed the current_time_wrapper branch 2 times, most recently from 7e3d98c to fdabd9b Compare July 26, 2025 08:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Reviewers

@TimWolla TimWolla TimWolla left review comments

@kocsismate kocsismate Awaiting requested review from kocsismate kocsismate is a code owner

@dstogov dstogov Awaiting requested review from dstogov dstogov is a code owner

@bukka bukka Awaiting requested review from bukka bukka is a code owner

@nielsdos nielsdos Awaiting requested review from nielsdos nielsdos is a code owner

@Girgias Girgias Awaiting requested review from Girgias Girgias is a code owner

@zeriyoshi zeriyoshi Awaiting requested review from zeriyoshi zeriyoshi is a code owner

@kamil-tekiela kamil-tekiela Awaiting requested review from kamil-tekiela kamil-tekiela is a code owner

@SakiTakamachi SakiTakamachi Awaiting requested review from SakiTakamachi SakiTakamachi is a code owner

@derickr derickr Awaiting requested review from derickr derickr is a code owner

@devnexen devnexen Awaiting requested review from devnexen devnexen is a code owner

Assignees
No one assigned
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

time() and friends have Y2038 problem on 64 Windows

AltStyle によって変換されたページ (->オリジナル) /