-
Notifications
You must be signed in to change notification settings - Fork 8k
Refactor Internal Time Retrieval Handling for Improved Consistency and Resolution #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
base: master
Are you sure you want to change the base?
Conversation
c81c27f to
8c044c8
Compare
315f346 to
956b7a0
Compare
956b7a0 to
88ec473
Compare
88ec473 to
abf0e46
Compare
TimWolla
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Had a rudimentary first look.
TimWolla
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some more bits. I'm approximately halfway through the PR. Feel free to already make the requested changes with regard to the removal of the macros, this probably saves us both a review cycle.
I'll be able to continue my work on it from tomorrow evening. |
8949f1a to
5dac1fe
Compare
|
Hi @TimWolla , I have now addressed all your comments. PS: I decided to not inline |
13a933b to
bf46488
Compare
|
@TimWolla rebased again - is this good to go now? - Should I squash the commits? |
|
@TimWolla It would be awesome if this could be merged |
371f94e to
c3e56a1
Compare
Introducing a more consistent and portable approach. The primary goals are to encapsulate platform-specific differences, improve time resolution, and prepare for long-term compatibility (e.g., Y2038 on WIN64).
c3e56a1 to
e4b56b4
Compare
bukka
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks mostly good but I think this should be split to smaller PR's. It might also help to get those changes merged as preference here should be to get reviews from code owners and if it's as big as this, it's kind of hard to get it.
| } | ||
| #endif | ||
|
|
||
| if (0 > fpm_clock_init()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What abou that mac specific handling
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
zend_time_mono_fallback is using zend_hrtime which already handles mac specifics in a better way (like clock_gettime_nsec_np)
|
|
||
| #include "fpm_config.h" | ||
|
|
||
| #include "zend_time.h" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not really sure if there is a big benefit in replacing fpm_clock.h here. In general those pieces of FPM should stay independent from Zend code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The SAPIs are already using Zend code - So they are not independent
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FPM has got some parts using Zend but the majority is independent.
|
I think this needs a bit deeper review and a bit of research for me to confidentily approve it. It might take me some time. As I noted spliting that to smaller parts might be a better way how to get it merged. |
OK, I'll can split out the SAPI changes for now.
What about moving this into main as |
This pull request refactors how PHP internally handles current time retrieval and time measurement, introducing a more consistent and portable approach. The primary goals are to encapsulate platform-specific differences, improve time resolution, and prepare for long-term compatibility (e.g., Y2038 on WIN64).
Key Changes
Introduced
zend_time.hA new internal header that abstracts system time functions, replacing direct usage of
<time.h>and related platform-specific APIs.Added
zend_time_real_specA unified wrapper around
clock_gettime(),timespec_get(),gettimeofday(), andtime()using the real/wall clock.Returns a
timespecstructure with nanosecond precision (when available).Added
zend_time_real_getA lightweight wrapper around
time(NULL)for simple, low-resolution time retrieval.Added
zend_time_mono_fallbackA wrapper for
zend_hrtimeor falls back tozend_time_real_spec.Useful for time measurements (e.g. timeout handling) where monotonic time is preferred, but wall time is an acceptable fallback.
Added helper functions
Added utilities to simplify usage of
timevalandtimespecstructures.Replaced direct system time API usage
Internal calls to system time functions now use
zend_time_*.Standardized time representation
Transitioned to
timespecfor current time where appropriate, while retainingtimevalfor files and stream-related functionality.Benefits
Improved Portability and Readability
Platform-specific time logic is encapsulated, reducing conditionals and improving clarity.
Guaranteed Time API Availability
The new abstraction ensures time can always be retrieved via a fallback chain:
clock_gettime()→timespec_get()→gettimeofday()→time()Y2038 Compatibility on WIN64
Addresses issues caused by
longintimeval.tv_secon 64-bit Windows systems.Improved Resolution for Time Functions
microtime()andgettimeofday(true)now offer better time precision without breaking backward compatibility.Removed Redundant Availability Checks
Previously unverified use of
gettimeofday()has been replaced by a robust fallback mechanism.Conditional checks for
microtime(),gettimeofday(), anduniqid()have been removed.