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

Commit 13d63a9

Browse files
Refactor basic time
1 parent 719419a commit 13d63a9

33 files changed

+397
-427
lines changed

‎Zend/Optimizer/zend_func_infos.h‎

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -559,10 +559,8 @@ static const func_info_t func_infos[] = {
559559
F1("dechex", MAY_BE_STRING),
560560
F1("base_convert", MAY_BE_STRING),
561561
F1("number_format", MAY_BE_STRING),
562-
#if defined(HAVE_GETTIMEOFDAY)
563562
F1("microtime", MAY_BE_STRING|MAY_BE_DOUBLE),
564563
F1("gettimeofday", MAY_BE_ARRAY|MAY_BE_ARRAY_KEY_STRING|MAY_BE_ARRAY_OF_LONG|MAY_BE_DOUBLE),
565-
#endif
566564
#if defined(HAVE_GETRUSAGE)
567565
F1("getrusage", MAY_BE_ARRAY|MAY_BE_ARRAY_KEY_STRING|MAY_BE_ARRAY_OF_LONG|MAY_BE_FALSE),
568566
#endif
@@ -597,9 +595,7 @@ static const func_info_t func_infos[] = {
597595
F1("stream_resolve_include_path", MAY_BE_STRING|MAY_BE_FALSE),
598596
F1("stream_get_wrappers", MAY_BE_ARRAY|MAY_BE_ARRAY_KEY_LONG|MAY_BE_ARRAY_OF_STRING),
599597
F1("stream_get_transports", MAY_BE_ARRAY|MAY_BE_ARRAY_KEY_LONG|MAY_BE_ARRAY_OF_STRING),
600-
#if defined(HAVE_GETTIMEOFDAY)
601598
F1("uniqid", MAY_BE_STRING),
602-
#endif
603599
F1("parse_url", MAY_BE_LONG|MAY_BE_STRING|MAY_BE_ARRAY|MAY_BE_ARRAY_KEY_STRING|MAY_BE_ARRAY_OF_LONG|MAY_BE_ARRAY_OF_STRING|MAY_BE_NULL|MAY_BE_FALSE),
604600
F1("urlencode", MAY_BE_STRING),
605601
F1("urldecode", MAY_BE_STRING),

‎configure.ac‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -529,6 +529,8 @@ AC_CHECK_FUNCS(m4_normalize([
529529
asctime_r
530530
asprintf
531531
chroot
532+
clock_gettime
533+
clock_getres
532534
ctime_r
533535
explicit_memset
534536
fdatasync
@@ -580,6 +582,8 @@ AC_CHECK_FUNCS(m4_normalize([
580582
strptime
581583
strtok_r
582584
symlink
585+
timespec_get
586+
timespec_getres
583587
tzset
584588
unsetenv
585589
usleep
@@ -1648,6 +1652,7 @@ PHP_ADD_SOURCES([main], m4_normalize([
16481652
php_scandir.c
16491653
php_syslog.c
16501654
php_ticks.c
1655+
php_time.c
16511656
php_variables.c
16521657
reentrancy.c
16531658
rfc1867.c

‎docs-old/streams.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ PHPAPI php_stream *php_stream_sock_open_from_socket(int socket, int persistent);
9090
/* Convert a socket into a stream. */
9191
9292
PHPAPI php_stream *php_stream_sock_open_host(const char *host, unsigned short port,
93-
int socktype, int timeout, int persistent);
93+
int socktype, struct timeval *timeout, const char *persistent_id);
9494
/* Open a connection to a host and return a stream. */
9595
9696
PHPAPI php_stream *php_stream_sock_open_unix(const char *path, int persistent,

‎ext/date/php_date.c‎

Lines changed: 4 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include "php.h"
1818
#include "php_main.h"
1919
#include "php_ini.h"
20+
#include "php_time.h"
2021
#include "ext/standard/info.h"
2122
#include "ext/standard/php_versioning.h"
2223
#include "php_date.h"
@@ -25,11 +26,6 @@
2526
#include "zend_exceptions.h"
2627
#include "lib/timelib.h"
2728
#include "lib/timelib_private.h"
28-
#ifndef PHP_WIN32
29-
#include <time.h>
30-
#else
31-
#include "win32/time.h"
32-
#endif
3329

3430
#ifdef PHP_WIN32
3531
static __inline __int64 php_date_llabs( __int64 i ) { return i >= 0? i: -i; }
@@ -55,18 +51,7 @@ static inline long long php_date_llabs( long long i ) { return i >= 0 ? i : -i;
5551

5652
PHPAPI time_t php_time(void)
5753
{
58-
#ifdef HAVE_GETTIMEOFDAY
59-
struct timeval tm;
60-
61-
if (UNEXPECTED(gettimeofday(&tm, NULL) != SUCCESS)) {
62-
/* fallback, can't reasonably happen */
63-
return time(NULL);
64-
}
65-
66-
return tm.tv_sec;
67-
#else
6854
return time(NULL);
69-
#endif
7055
}
7156

7257
/*
@@ -2353,16 +2338,9 @@ static void php_date_set_time_fraction(timelib_time *time, int microsecond)
23532338

23542339
static void php_date_get_current_time_with_fraction(time_t *sec, suseconds_t *usec)
23552340
{
2356-
#ifdef HAVE_GETTIMEOFDAY
2357-
struct timeval tp = {0}; /* For setting microsecond */
2358-
2359-
gettimeofday(&tp, NULL);
2360-
*sec = tp.tv_sec;
2361-
*usec = tp.tv_usec;
2362-
#else
2363-
*sec = time(NULL);
2364-
*usec = 0;
2365-
#endif
2341+
long nsec;
2342+
php_realtime_get(sec, &nsec);
2343+
*usec = nsec / 1000;
23662344
}
23672345

23682346
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/ftp/ftp.c‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#endif
2121

2222
#include "php.h"
23+
#include <php_time.h>
2324

2425
#include <stdio.h>
2526
#include <ctype.h>
@@ -29,7 +30,6 @@
2930
#endif
3031
#include <fcntl.h>
3132
#include <string.h>
32-
#include <time.h>
3333
#ifdef PHP_WIN32
3434
#include <winsock2.h>
3535
#else
@@ -1608,8 +1608,7 @@ static databuf_t* ftp_getdata(ftpbuf_t *ftp)
16081608
/* connect */
16091609
/* Win 95/98 seems not to like size > sizeof(sockaddr_in) */
16101610
size = php_sockaddr_size(&ftp->pasvaddr);
1611-
tv.tv_sec = ftp->timeout_sec;
1612-
tv.tv_usec = 0;
1611+
php_timei2val(ftp->timeout_sec, tv);
16131612
if (php_connect_nonb(fd, (struct sockaddr*) &ftp->pasvaddr, size, &tv) == -1) {
16141613
php_error_docref(NULL, E_WARNING, "php_connect_nonb() failed: %s (%d)", strerror(errno), errno);
16151614
goto bail;

‎ext/mysqlnd/mysqlnd_debug.c‎

Lines changed: 27 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
*/
1717

1818
#include "php.h"
19+
#include "php_time.h"
1920
#include "mysqlnd.h"
2021
#include "mysqlnd_priv.h"
2122
#include "mysqlnd_debug.h"
@@ -76,21 +77,19 @@ MYSQLND_METHOD(mysqlnd_debug, log)(MYSQLND_DEBUG * self,
7677
}
7778
if (flags & MYSQLND_DEBUG_DUMP_TIME) {
7879
/* The following from FF's DBUG library, which is in the public domain */
79-
struct timevaltv;
80+
struct timespects;
8081
struct tm *tm_p;
81-
if (gettimeofday(&tv, NULL) != -1) {
82-
const time_t sec = tv.tv_sec;
83-
if ((tm_p = localtime((const time_t *)&sec))) {
84-
snprintf(time_buffer, sizeof(time_buffer) - 1,
85-
/* "%04d-%02d-%02d " */
86-
"%02d:%02d:%02d.%06d ",
87-
/*tm_p->tm_year + 1900, tm_p->tm_mon + 1, tm_p->tm_mday,*/
88-
tm_p->tm_hour, tm_p->tm_min, tm_p->tm_sec,
89-
(int) (tv.tv_usec));
90-
time_buffer[sizeof(time_buffer) - 1 ] = '0円';
91-
} else {
92-
time_buffer[0] = '0円';
93-
}
82+
php_realtime_spec(&ts);
83+
if ((tm_p = localtime((const time_t *)&ts.tv_sec))) {
84+
snprintf(time_buffer, sizeof(time_buffer) - 1,
85+
/* "%04d-%02d-%02d " */
86+
"%02d:%02d:%02d.%06d ",
87+
/*tm_p->tm_year + 1900, tm_p->tm_mon + 1, tm_p->tm_mday,*/
88+
tm_p->tm_hour, tm_p->tm_min, tm_p->tm_sec,
89+
(int) (ts.tv_nsec / 1000));
90+
time_buffer[sizeof(time_buffer) - 1 ] = '0円';
91+
} else {
92+
time_buffer[0] = '0円';
9493
}
9594
}
9695
if (flags & MYSQLND_DEBUG_DUMP_FILE) {
@@ -163,21 +162,19 @@ MYSQLND_METHOD(mysqlnd_debug, log_va)(MYSQLND_DEBUG *self,
163162
}
164163
if (flags & MYSQLND_DEBUG_DUMP_TIME) {
165164
/* The following from FF's DBUG library, which is in the public domain */
166-
struct timevaltv;
165+
struct timespects;
167166
struct tm *tm_p;
168-
if (gettimeofday(&tv, NULL) != -1) {
169-
const time_t sec = tv.tv_sec;
170-
if ((tm_p = localtime((const time_t *)&sec))) {
171-
snprintf(time_buffer, sizeof(time_buffer) - 1,
172-
/* "%04d-%02d-%02d " */
173-
"%02d:%02d:%02d.%06d ",
174-
/*tm_p->tm_year + 1900, tm_p->tm_mon + 1, tm_p->tm_mday,*/
175-
tm_p->tm_hour, tm_p->tm_min, tm_p->tm_sec,
176-
(int) (tv.tv_usec));
177-
time_buffer[sizeof(time_buffer) - 1 ] = '0円';
178-
} else {
179-
time_buffer[0] = '0円';
180-
}
167+
php_realtime_spec(&ts);
168+
if ((tm_p = localtime((const time_t *)&ts.tv_sec))) {
169+
snprintf(time_buffer, sizeof(time_buffer) - 1,
170+
/* "%04d-%02d-%02d " */
171+
"%02d:%02d:%02d.%06d ",
172+
/*tm_p->tm_year + 1900, tm_p->tm_mon + 1, tm_p->tm_mday,*/
173+
tm_p->tm_hour, tm_p->tm_min, tm_p->tm_sec,
174+
(int)(ts.tv_nsec / 1000));
175+
time_buffer[sizeof(time_buffer) - 1 ] = '0円';
176+
} else {
177+
time_buffer[0] = '0円';
181178
}
182179
}
183180
if (flags & MYSQLND_DEBUG_DUMP_FILE) {
@@ -329,8 +326,8 @@ MYSQLND_METHOD(mysqlnd_debug, func_leave)(MYSQLND_DEBUG * self, unsigned int lin
329326
uint64_t own_time = call_time - mine_non_own_time;
330327
uint32_t func_name_len = strlen(*func_name);
331328

332-
self->m->log_va(self, line, file, zend_stack_count(&self->call_stack) - 1, NULL, "<%s (total=%u own=%u in_calls=%u)",
333-
*func_name, (unsigned int) call_time, (unsigned int) own_time, (unsigned int) mine_non_own_time
329+
self->m->log_va(self, line, file, zend_stack_count(&self->call_stack) - 1, NULL, "<%s (total=%"PRIu64" own=%"PRIu64" in_calls=%"PRIu64")",
330+
*func_name, call_time, own_time, mine_non_own_time
334331
);
335332

336333
if ((f_profile = zend_hash_str_find_ptr(&self->function_profiles, *func_name, func_name_len)) != NULL) {

‎ext/mysqlnd/mysqlnd_debug.h‎

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -80,18 +80,16 @@ PHPAPI MYSQLND_DEBUG * mysqlnd_debug_init(const char * skip_functions[]);
8080

8181

8282
#if defined(__GNUC__) || defined(PHP_WIN32)
83-
#ifdef PHP_WIN32
84-
#include "win32/time.h"
85-
#else
86-
#include <sys/time.h>
87-
#endif
83+
#include "php_time.h"
8884

8985
#ifndef MYSQLND_PROFILING_DISABLED
90-
#define DBG_PROFILE_TIMEVAL_TO_DOUBLE(tp) ((tp.tv_sec * 1000000LL)+ tp.tv_usec)
91-
#define DBG_PROFILE_START_TIME() gettimeofday(&__dbg_prof_tp, NULL); __dbg_prof_start = DBG_PROFILE_TIMEVAL_TO_DOUBLE(__dbg_prof_tp);
92-
#define DBG_PROFILE_END_TIME(duration) gettimeofday(&__dbg_prof_tp, NULL); (duration) = (DBG_PROFILE_TIMEVAL_TO_DOUBLE(__dbg_prof_tp) - __dbg_prof_start);
86+
#define DBG_PROFILE_START_TIME() \
87+
php_realtime_spec(&__dbg_prof_ts); \
88+
__dbg_prof_start = (uint64_t)(__dbg_prof_ts.tv_sec * UINT64_C(1000000000) + __dbg_prof_ts.tv_nsec);
89+
#define DBG_PROFILE_END_TIME(duration) \
90+
php_realtime_spec(&__dbg_prof_ts); \
91+
(duration) = (uint64_t)(__dbg_prof_ts.tv_sec * UINT64_C(1000000000) + __dbg_prof_ts.tv_nsec) - __dbg_prof_start;
9392
#else
94-
#define DBG_PROFILE_TIMEVAL_TO_DOUBLE(tp)
9593
#define DBG_PROFILE_START_TIME()
9694
#define DBG_PROFILE_END_TIME(duration)
9795
#endif
@@ -117,7 +115,7 @@ PHPAPI MYSQLND_DEBUG * mysqlnd_debug_init(const char * skip_functions[]);
117115
#define DBG_LEAVE_EX(dbg_obj, leave) DBG_LEAVE_EX2((dbg_obj), (MYSQLND_DEBUG *) NULL, leave)
118116

119117
#define DBG_ENTER_EX2(dbg_obj1, dbg_obj2, func_name) \
120-
struct timeval __dbg_prof_tp = {0}; \
118+
struct timespec __dbg_prof_ts; \
121119
uint64_t __dbg_prof_start = 0; /* initialization is needed */ \
122120
bool dbg_skip_trace = TRUE; \
123121
((void)__dbg_prof_start); \

‎ext/mysqlnd/mysqlnd_vio.c‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -204,8 +204,7 @@ MYSQLND_METHOD(mysqlnd_vio, open_tcp_or_unix)(MYSQLND_VIO * const vio, const MYS
204204
}
205205

206206
if (vio->data->options.timeout_connect) {
207-
tv.tv_sec = vio->data->options.timeout_connect;
208-
tv.tv_usec = 0;
207+
php_timei2val(vio->data->options.timeout_connect, tv);
209208
}
210209

211210
DBG_INF_FMT("calling php_stream_xport_create");

0 commit comments

Comments
(0)

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