Skip to content

Commit d7ffbbf

Browse files
committed
Replace php_time() with zend_realtime_get()
1 parent 9bcfa57 commit d7ffbbf

File tree

3 files changed

+18
-20
lines changed

3 files changed

+18
-20
lines changed

ext/date/php_date.c

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,6 @@ static inline long long php_date_llabs( long long i ) { return i >= 0 ? i : -i;
4949
#define DATE_A64I(i, s) i = strtoll(s, NULL, 10)
5050
#endif
5151

52-
PHPAPI time_t php_time(void)
53-
{
54-
return time(NULL);
55-
}
56-
5752
/*
5853
* RFC822, Section 5.1: http://www.ietf.org/rfc/rfc822.txt
5954
* date-time = [ day "," ] date time ; dd mm yy hh:mm:ss zzz
@@ -852,7 +847,7 @@ static void php_date(INTERNAL_FUNCTION_PARAMETERS, bool localtime)
852847
ZEND_PARSE_PARAMETERS_END();
853848

854849
if (ts_is_null) {
855-
ts = php_time();
850+
ts = zend_realtime_get(NULL, NULL);
856851
}
857852

858853
RETURN_STR(php_format_date(ZSTR_VAL(format), ZSTR_LEN(format), ts, localtime));
@@ -1016,7 +1011,7 @@ PHP_FUNCTION(idate)
10161011
}
10171012

10181013
if (ts_is_null) {
1019-
ts = php_time();
1014+
ts = zend_realtime_get(NULL, NULL);
10201015
}
10211016

10221017
ret = php_idate(ZSTR_VAL(format)[0], ts, 0);
@@ -1096,7 +1091,7 @@ PHP_FUNCTION(strtotime)
10961091
now->tz_info = tzi;
10971092
now->zone_type = TIMELIB_ZONETYPE_ID;
10981093
timelib_unixtime2local(now,
1099-
!preset_ts_is_null ? (timelib_sll) preset_ts : (timelib_sll) php_time());
1094+
!preset_ts_is_null ? (timelib_sll) preset_ts : (timelib_sll) zend_realtime_get(NULL, NULL));
11001095

11011096
t = timelib_strtotime(ZSTR_VAL(times), ZSTR_LEN(times), &error,
11021097
DATE_TIMEZONEDB, php_date_parse_tzfile_wrapper);
@@ -1147,15 +1142,15 @@ PHPAPI void php_mktime(INTERNAL_FUNCTION_PARAMETERS, bool gmt)
11471142
/* Initialize structure with current time */
11481143
now = timelib_time_ctor();
11491144
if (gmt) {
1150-
timelib_unixtime2gmt(now, (timelib_sll) php_time());
1145+
timelib_unixtime2gmt(now, (timelib_sll) zend_realtime_get(NULL, NULL));
11511146
} else {
11521147
tzi = get_timezone_info();
11531148
if (!tzi) {
11541149
return;
11551150
}
11561151
now->tz_info = tzi;
11571152
now->zone_type = TIMELIB_ZONETYPE_ID;
1158-
timelib_unixtime2local(now, (timelib_sll) php_time());
1153+
timelib_unixtime2local(now, (timelib_sll) zend_realtime_get(NULL, NULL));
11591154
}
11601155

11611156
now->h = hou;
@@ -1265,7 +1260,7 @@ PHPAPI void php_strftime(INTERNAL_FUNCTION_PARAMETERS, bool gmt)
12651260
}
12661261

12671262
if (timestamp_is_null) {
1268-
timestamp = (zend_long) php_time();
1263+
timestamp = (zend_long) zend_realtime_get(NULL, NULL);
12691264
}
12701265

12711266
ts = timelib_time_ctor();
@@ -1361,7 +1356,7 @@ PHP_FUNCTION(time)
13611356
{
13621357
ZEND_PARSE_PARAMETERS_NONE();
13631358

1364-
RETURN_LONG((zend_long)php_time());
1359+
RETURN_LONG((zend_long) zend_realtime_get(NULL, NULL));
13651360
}
13661361
/* }}} */
13671362

@@ -1381,7 +1376,7 @@ PHP_FUNCTION(localtime)
13811376
ZEND_PARSE_PARAMETERS_END();
13821377

13831378
if (timestamp_is_null) {
1384-
timestamp = (zend_long) php_time();
1379+
timestamp = (zend_long) zend_realtime_get(NULL, NULL);
13851380
}
13861381

13871382
tzi = get_timezone_info();
@@ -1436,7 +1431,7 @@ PHP_FUNCTION(getdate)
14361431
ZEND_PARSE_PARAMETERS_END();
14371432

14381433
if (timestamp_is_null) {
1439-
timestamp = (zend_long) php_time();
1434+
timestamp = (zend_long) zend_realtime_get(NULL, NULL);
14401435
}
14411436

14421437
tzi = get_timezone_info();
@@ -2338,9 +2333,11 @@ static void php_date_set_time_fraction(timelib_time *time, int microsecond)
23382333

23392334
static void php_date_get_current_time_with_fraction(time_t *sec, suseconds_t *usec)
23402335
{
2341-
long nsec;
2342-
zend_realtime_get(sec, &nsec);
2343-
*usec = nsec / 1000;
2336+
struct timespec ts;
2337+
2338+
zend_realtime_spec(&ts);
2339+
*sec = ts.tv_sec;
2340+
*usec = ts.tv_nsec / 1000;
23442341
}
23452342

23462343
PHPAPI bool php_date_initialize(php_date_obj *dateobj, const char *time_str, size_t time_str_len, const char *format, zval *timezone_object, int flags) /* {{{ */

ext/date/php_date.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,8 @@ ZEND_END_MODULE_GLOBALS(date)
129129

130130
#define DATEG(v) ZEND_MODULE_GLOBALS_ACCESSOR(date, v)
131131

132-
PHPAPI time_t php_time(void);
132+
/* DEPRECATED, use zend_realtime_get(NULL, NULL) instead */
133+
#define php_time() zend_realtime_get(NULL, NULL)
133134

134135
/* Backwards compatibility wrapper */
135136
PHPAPI zend_long php_parse_date(const char *string, zend_long *now);

ext/standard/head.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
#include "SAPI.h"
2222
#include "php_main.h"
2323
#include "head.h"
24-
#include <time.h>
24+
#include "zend_time.h"
2525

2626
#include "php_globals.h"
2727
#include "zend_smart_str.h"
@@ -155,7 +155,7 @@ PHPAPI zend_result php_setcookie(zend_string *name, zend_string *value, time_t e
155155
smart_str_append(&buf, dt);
156156
zend_string_free(dt);
157157

158-
diff = difftime(expires, php_time());
158+
diff = difftime(expires, zend_realtime_get(NULL, NULL));
159159
if (diff < 0) {
160160
diff = 0;
161161
}

0 commit comments

Comments
 (0)