-
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
Open
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
eb90bfc
Refactor basic time
marc-mabe 17f3e49
sapi/litespeed
marc-mabe 02bb870
ext/ftp: prefer zend_monotime_fallback over zend_hrtime for timeout h...
marc-mabe e9f34a1
Replace php_time() with zend_realtime_get()
marc-mabe 3c341ff
Convert zend_realtime_get() to be a macro wrapper around time(NULL)
marc-mabe 88ec473
Replace time() in favor of zend_realtime_get()
marc-mabe File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
Zend/zend_time.c
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/* | ||
+----------------------------------------------------------------------+ | ||
| Copyright (c) The PHP Group | | ||
+----------------------------------------------------------------------+ | ||
| This source file is subject to version 3.01 of the PHP license, | | ||
| that is bundled with this package in the file LICENSE, and is | | ||
| available through the world-wide-web at the following url: | | ||
| https://www.php.net/license/3_01.txt | | ||
| If you did not receive a copy of the PHP license and are unable to | | ||
| obtain it through the world-wide-web, please send a note to | | ||
| license@php.net so we can mail you a copy immediately. | | ||
+----------------------------------------------------------------------+ | ||
| Author: Marc Bennewitz <marc@mabe.berlin> | | ||
+----------------------------------------------------------------------+ | ||
*/ | ||
|
||
#include "zend_time.h" | ||
|
||
ZEND_API void zend_realtime_spec(struct timespec *ts) { | ||
#if defined(HAVE_CLOCK_GETTIME) | ||
|
||
clock_gettime(CLOCK_REALTIME, ts); | ||
|
||
#elif defined(HAVE_TIMESPEC_GET) | ||
|
||
timespec_get(ts, TIME_UTC); | ||
|
||
#elif defined(HAVE_GETTIMEOFDAY) | ||
|
||
struct timeval tv; | ||
gettimeofday(&tv, NULL); | ||
zend_time_val2spec(tv, ts); | ||
|
||
#else | ||
|
||
ts->tv_sec = zend_realtime_get(); | ||
ts->tv_nsec = 0; | ||
|
||
#endif | ||
} |
85 changes: 85 additions & 0 deletions
Zend/zend_time.h
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
/* | ||
+----------------------------------------------------------------------+ | ||
| Copyright (c) The PHP Group | | ||
+----------------------------------------------------------------------+ | ||
| This source file is subject to version 3.01 of the PHP license, | | ||
| that is bundled with this package in the file LICENSE, and is | | ||
| available through the world-wide-web at the following url: | | ||
| https://www.php.net/license/3_01.txt | | ||
| If you did not receive a copy of the PHP license and are unable to | | ||
| obtain it through the world-wide-web, please send a note to | | ||
| license@php.net so we can mail you a copy immediately. | | ||
+----------------------------------------------------------------------+ | ||
| Author: Marc Bennewitz <marc@mabe.berlin> | | ||
+----------------------------------------------------------------------+ | ||
*/ | ||
|
||
#ifndef ZEND_TIME_H | ||
#define ZEND_TIME_H | ||
|
||
#include "zend_portability.h" | ||
|
||
#ifdef PHP_WIN32 | ||
# include "win32/time.h" | ||
#endif | ||
#ifdef HAVE_SYS_TIME_H | ||
# include <sys/time.h> | ||
#endif | ||
#include <time.h> | ||
|
||
#include "zend_hrtime.h" | ||
|
||
#ifndef PHP_WIN32 | ||
# define tv_sec_t time_t | ||
# define tv_usec_t suseconds_t | ||
#else | ||
# define tv_sec_t long | ||
# define tv_usec_t long | ||
#endif | ||
|
||
#define ZEND_MILLI_IN_SEC 1000U | ||
#define ZEND_MICRO_IN_SEC 1000000U | ||
|
||
/* Helper macro to assign seconds to timeval */ | ||
#define zend_time_sec2val(s, tv) \ | ||
(tv).tv_sec = (tv_sec_t) (s); \ | ||
(tv).tv_usec = 0; | ||
|
||
/* Helper macro to assign microseconds to timeval */ | ||
#define zend_time_usec2val(usec, tv) \ | ||
(tv).tv_sec = (tv_sec_t) ((usec) / ZEND_MICRO_IN_SEC); \ | ||
(tv).tv_usec = (tv_usec_t) ((usec) % ZEND_MICRO_IN_SEC); | ||
|
||
/* Helper macro to assign double (seconds) to timeval */ | ||
#define zend_time_dbl2val(d, tv) \ | ||
(tv).tv_sec = (tv_sec_t) (d); \ | ||
(tv).tv_usec = (tv_usec_t) (((d) - (tv).tv_sec) * ZEND_MICRO_IN_SEC); | ||
|
||
/* Helper macro to copy timeval to timespec */ | ||
#define zend_time_val2spec(tv, ts) \ | ||
(ts).tv_sec = (time_t) (tv).tv_sec; \ | ||
(ts).tv_nsec = (long) ((tv).tv_usec * 1000); | ||
|
||
BEGIN_EXTERN_C() | ||
|
||
/* Helper macro to get current timestamp in seconds */ | ||
#define zend_realtime_get() time(NULL) | ||
|
||
/* wrapper around clock_gettime/timestamp_get/gettimeofday/time */ | ||
ZEND_API void zend_realtime_spec(struct timespec *ts); | ||
|
||
/* Monotonic time in nanoseconds with a fallback to real/wall-time | ||
if no monotonic timer is available */ | ||
#if ZEND_HRTIME_AVAILABLE | ||
# define zend_monotime_fallback() (uint64_t)zend_hrtime() | ||
#else | ||
ZEND_API zend_always_inline uint64_t zend_monotime_fallback(void) { | ||
struct timespec ts; | ||
zend_realtime_spec(&ts); | ||
return ((uint64_t) ts.tv_sec * ZEND_NANO_IN_SEC) + ts.tv_nsec; | ||
} | ||
#endif | ||
|
||
END_EXTERN_C() | ||
|
||
#endif // ZEND_TIME_H |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.