This source file includes following definitions.
- _php_gettimeofday
- PHP_FUNCTION
- PHP_FUNCTION
- PHP_FUNCTION
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 #include "php.h"
22
23 #ifdef HAVE_SYS_TYPES_H
24 #include <sys/types.h>
25 #endif
26 #ifdef PHP_WIN32
27 #include "win32/time.h"
28 #elif defined(NETWARE)
29 #include <sys/timeval.h>
30 #include <sys/time.h>
31 #else
32 #include <sys/time.h>
33 #endif
34 #ifdef HAVE_SYS_RESOURCE_H
35 #include <sys/resource.h>
36 #endif
37 #ifdef HAVE_UNISTD_H
38 #include <unistd.h>
39 #endif
40 #include <stdlib.h>
41 #include <string.h>
42 #include <stdio.h>
43 #include <errno.h>
44
45 #include "microtime.h"
46 #include "ext/date/php_date.h"
47
48 #define NUL '\0'
49 #define MICRO_IN_SEC 1000000.00
50 #define SEC_IN_MIN 60
51
52 #ifdef HAVE_GETTIMEOFDAY
53 static void _php_gettimeofday(INTERNAL_FUNCTION_PARAMETERS, int mode)
54 {
55 zend_bool get_as_float = 0;
56 struct timeval tp = {0};
57
58 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|b", &get_as_float) == FAILURE) {
59 return;
60 }
61
62 if (gettimeofday(&tp, NULL)) {
63 RETURN_FALSE;
64 }
65
66 if (get_as_float) {
67 RETURN_DOUBLE((double)(tp.tv_sec + tp.tv_usec / MICRO_IN_SEC));
68 }
69
70 if (mode) {
71 timelib_time_offset *offset;
72
73 offset = timelib_get_time_zone_info(tp.tv_sec, get_timezone_info(TSRMLS_C));
74
75 array_init(return_value);
76 add_assoc_long(return_value, "sec", tp.tv_sec);
77 add_assoc_long(return_value, "usec", tp.tv_usec);
78
79 add_assoc_long(return_value, "minuteswest", -offset->offset / SEC_IN_MIN);
80 add_assoc_long(return_value, "dsttime", offset->is_dst);
81
82 timelib_time_offset_dtor(offset);
83 } else {
84 char ret[100];
85
86 snprintf(ret, 100, "%.8F %ld", tp.tv_usec / MICRO_IN_SEC, tp.tv_sec);
87 RETURN_STRING(ret, 1);
88 }
89 }
90
91
92
93 PHP_FUNCTION(microtime)
94 {
95 _php_gettimeofday(INTERNAL_FUNCTION_PARAM_PASSTHRU, 0);
96 }
97
98
99
100
101 PHP_FUNCTION(gettimeofday)
102 {
103 _php_gettimeofday(INTERNAL_FUNCTION_PARAM_PASSTHRU, 1);
104 }
105 #endif
106
107
108 #ifdef HAVE_GETRUSAGE
109
110
111 PHP_FUNCTION(getrusage)
112 {
113 struct rusage usg;
114 long pwho = 0;
115 int who = RUSAGE_SELF;
116
117 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|l", &pwho) == FAILURE) {
118 return;
119 }
120
121 if (pwho == 1) {
122 who = RUSAGE_CHILDREN;
123 }
124
125 memset(&usg, 0, sizeof(struct rusage));
126
127 if (getrusage(who, &usg) == -1) {
128 RETURN_FALSE;
129 }
130
131 array_init(return_value);
132 #define PHP_RUSAGE_PARA(a) \
133 add_assoc_long(return_value, #a, usg.a)
134 #if !defined( _OSD_POSIX) && !defined(__BEOS__)
135 PHP_RUSAGE_PARA(ru_oublock);
136 PHP_RUSAGE_PARA(ru_inblock);
137 PHP_RUSAGE_PARA(ru_msgsnd);
138 PHP_RUSAGE_PARA(ru_msgrcv);
139 PHP_RUSAGE_PARA(ru_maxrss);
140 PHP_RUSAGE_PARA(ru_ixrss);
141 PHP_RUSAGE_PARA(ru_idrss);
142 PHP_RUSAGE_PARA(ru_minflt);
143 PHP_RUSAGE_PARA(ru_majflt);
144 PHP_RUSAGE_PARA(ru_nsignals);
145 PHP_RUSAGE_PARA(ru_nvcsw);
146 PHP_RUSAGE_PARA(ru_nivcsw);
147 PHP_RUSAGE_PARA(ru_nswap);
148 #endif
149 PHP_RUSAGE_PARA(ru_utime.tv_usec);
150 PHP_RUSAGE_PARA(ru_utime.tv_sec);
151 PHP_RUSAGE_PARA(ru_stime.tv_usec);
152 PHP_RUSAGE_PARA(ru_stime.tv_sec);
153 #undef PHP_RUSAGE_PARA
154 }
155 #endif
156
157
158
159
160
161
162
163
164
165
166