1 /*
2 +----------------------------------------------------------------------+
3 | PHP Version 5 |
4 +----------------------------------------------------------------------+
5 | Copyright (c) 2006-2013 The PHP Group |
6 +----------------------------------------------------------------------+
7 | This source file is subject to version 3.01 of the PHP license, |
8 | that is bundled with this package in the file LICENSE, and is |
9 | available through the world-wide-web at the following url: |
10 | http://www.php.net/license/3_01.txt |
11 | If you did not receive a copy of the PHP license and are unable to |
12 | obtain it through the world-wide-web, please send a note to |
13 | license@php.net so we can mail you a copy immediately. |
14 +----------------------------------------------------------------------+
15 | Authors: Georg Richter <georg@mysql.com> |
16 | Andrey Hristov <andrey@mysql.com> |
17 | Ulf Wendel <uwendel@mysql.com> |
18 +----------------------------------------------------------------------+
19 */
20
21 /* $Id$ */
22 #include "php.h"
23 #include "php_ini.h"
24 #include "mysqlnd.h"
25 #include "mysqlnd_priv.h"
26 #include "mysqlnd_debug.h"
27 #include "ext/standard/info.h"
28
29 /* {{{ mysqlnd_functions[]
30 *
31 * Every user visible function must have an entry in mysqlnd_functions[].
32 */
33 static zend_function_entry mysqlnd_functions[] = {
34 PHP_FE_END
35 };
36 /* }}} */
37
38
39 /* {{{ mysqlnd_minfo_print_hash */
40 #if MYSQLND_UNICODE
mysqlnd_minfo_print_hash(zval * values)41 PHPAPI void mysqlnd_minfo_print_hash(zval *values)
42 {
43 zval **values_entry;
44 HashPosition pos_values;
45
46 zend_hash_internal_pointer_reset_ex(Z_ARRVAL_P(values), &pos_values);
47 while (zend_hash_get_current_data_ex(Z_ARRVAL_P(values),
48 (void **)&values_entry, &pos_values) == SUCCESS) {
49 zstr string_key;
50 uint string_key_len;
51 ulong num_key;
52 int s_len;
53 char *s = NULL;
54
55 TSRMLS_FETCH();
56 zend_hash_get_current_key_ex(Z_ARRVAL_P(values), &string_key, &string_key_len, &num_key, 0, &pos_values);
57
58 convert_to_string(*values_entry);
59
60 if (zend_unicode_to_string(ZEND_U_CONVERTER(UG(runtime_encoding_conv)),
61 &s, &s_len, string_key.u, string_key_len TSRMLS_CC) == SUCCESS) {
62 php_info_print_table_row(2, s, Z_STRVAL_PP(values_entry));
63 }
64 if (s) {
65 mnd_efree(s);
66 }
67
68 zend_hash_move_forward_ex(Z_ARRVAL_P(values), &pos_values);
69 }
70 }
71 #else
mysqlnd_minfo_print_hash(zval * values)72 PHPAPI void mysqlnd_minfo_print_hash(zval *values)
73 {
74 zval **values_entry;
75 HashPosition pos_values;
76
77 zend_hash_internal_pointer_reset_ex(Z_ARRVAL_P(values), &pos_values);
78 while (zend_hash_get_current_data_ex(Z_ARRVAL_P(values), (void **)&values_entry, &pos_values) == SUCCESS) {
79 char *string_key;
80 uint string_key_len;
81 ulong num_key;
82
83 zend_hash_get_current_key_ex(Z_ARRVAL_P(values), &string_key, &string_key_len, &num_key, 0, &pos_values);
84
85 convert_to_string(*values_entry);
86 php_info_print_table_row(2, string_key, Z_STRVAL_PP(values_entry));
87
88 zend_hash_move_forward_ex(Z_ARRVAL_P(values), &pos_values);
89 }
90 }
91 #endif
92 /* }}} */
93
94
95 /* {{{ PHP_MINFO_FUNCTION
96 */
PHP_MINFO_FUNCTION(mysqlnd)97 PHP_MINFO_FUNCTION(mysqlnd)
98 {
99 char buf[32];
100 zval values;
101
102 php_info_print_table_start();
103 php_info_print_table_header(2, "mysqlnd", "enabled");
104 php_info_print_table_row(2, "Version", mysqlnd_get_client_info());
105 php_info_print_table_row(2, "Compression",
106 #ifdef MYSQLND_COMPRESSION_ENABLED
107 "supported");
108 #else
109 "not supported");
110 #endif
111 php_info_print_table_row(2, "SSL",
112 #ifdef MYSQLND_SSL_SUPPORTED
113 "supported");
114 #else
115 "not supported");
116 #endif
117 snprintf(buf, sizeof(buf), "%ld", MYSQLND_G(net_cmd_buffer_size));
118 php_info_print_table_row(2, "Command buffer size", buf);
119 snprintf(buf, sizeof(buf), "%ld", MYSQLND_G(net_read_buffer_size));
120 php_info_print_table_row(2, "Read buffer size", buf);
121 snprintf(buf, sizeof(buf), "%ld", MYSQLND_G(net_read_timeout));
122 php_info_print_table_row(2, "Read timeout", buf);
123 php_info_print_table_row(2, "Collecting statistics", MYSQLND_G(collect_statistics)? "Yes":"No");
124 php_info_print_table_row(2, "Collecting memory statistics", MYSQLND_G(collect_memory_statistics)? "Yes":"No");
125
126 php_info_print_table_row(2, "Tracing", MYSQLND_G(debug)? MYSQLND_G(debug):"n/a");
127 php_info_print_table_end();
128
129 /* Print client stats */
130 php_info_print_table_start();
131 php_info_print_table_header(2, "Client statistics", "");
132 mysqlnd_get_client_stats(&values);
133 mysqlnd_minfo_print_hash(&values);
134
135 zval_dtor(&values);
136 php_info_print_table_end();
137 }
138 /* }}} */
139
140
ZEND_DECLARE_MODULE_GLOBALS(mysqlnd)141 PHPAPI ZEND_DECLARE_MODULE_GLOBALS(mysqlnd)
142
143
144 /* {{{ PHP_GINIT_FUNCTION
145 */
146 static PHP_GINIT_FUNCTION(mysqlnd)
147 {
148 mysqlnd_globals->collect_statistics = TRUE;
149 mysqlnd_globals->collect_memory_statistics = FALSE;
150 mysqlnd_globals->debug = NULL; /* The actual string */
151 mysqlnd_globals->dbg = NULL; /* The DBG object*/
152 mysqlnd_globals->net_cmd_buffer_size = MYSQLND_NET_CMD_BUFFER_MIN_SIZE;
153 mysqlnd_globals->net_read_buffer_size = 32768;
154 mysqlnd_globals->net_read_timeout = 31536000;
155 mysqlnd_globals->log_mask = 0;
156 mysqlnd_globals->mempool_default_size = 16000;
157 mysqlnd_globals->debug_emalloc_fail_threshold = -1;
158 mysqlnd_globals->debug_ecalloc_fail_threshold = -1;
159 mysqlnd_globals->debug_erealloc_fail_threshold = -1;
160 mysqlnd_globals->debug_malloc_fail_threshold = -1;
161 mysqlnd_globals->debug_calloc_fail_threshold = -1;
162 mysqlnd_globals->debug_realloc_fail_threshold = -1;
163 }
164 /* }}} */
165
166
PHP_INI_MH(OnUpdateNetCmdBufferSize)167 static PHP_INI_MH(OnUpdateNetCmdBufferSize)
168 {
169 long long_value = atol(new_value);
170 if (long_value < MYSQLND_NET_CMD_BUFFER_MIN_SIZE) {
171 return FAILURE;
172 }
173 MYSQLND_G(net_cmd_buffer_size) = long_value;
174
175 return SUCCESS;
176 }
177
178 /* {{{ PHP_INI_BEGIN
179 */
180 PHP_INI_BEGIN()
181 STD_PHP_INI_BOOLEAN("mysqlnd.collect_statistics", "1", PHP_INI_ALL, OnUpdateBool, collect_statistics, zend_mysqlnd_globals, mysqlnd_globals)
182 STD_PHP_INI_BOOLEAN("mysqlnd.collect_memory_statistics", "0", PHP_INI_SYSTEM, OnUpdateBool, collect_memory_statistics, zend_mysqlnd_globals, mysqlnd_globals)
183 STD_PHP_INI_ENTRY("mysqlnd.debug", NULL, PHP_INI_SYSTEM, OnUpdateString, debug, zend_mysqlnd_globals, mysqlnd_globals)
184 STD_PHP_INI_ENTRY("mysqlnd.net_cmd_buffer_size", MYSQLND_NET_CMD_BUFFER_MIN_SIZE_STR, PHP_INI_ALL, OnUpdateNetCmdBufferSize, net_cmd_buffer_size, zend_mysqlnd_globals, mysqlnd_globals)
185 STD_PHP_INI_ENTRY("mysqlnd.net_read_buffer_size", "32768",PHP_INI_ALL, OnUpdateLong, net_read_buffer_size, zend_mysqlnd_globals, mysqlnd_globals)
186 STD_PHP_INI_ENTRY("mysqlnd.net_read_timeout", "31536000", PHP_INI_SYSTEM, OnUpdateLong, net_read_timeout, zend_mysqlnd_globals, mysqlnd_globals)
187 STD_PHP_INI_ENTRY("mysqlnd.log_mask", "0", PHP_INI_ALL, OnUpdateLong, log_mask, zend_mysqlnd_globals, mysqlnd_globals)
188 STD_PHP_INI_ENTRY("mysqlnd.mempool_default_size","16000", PHP_INI_ALL, OnUpdateLong, mempool_default_size, zend_mysqlnd_globals, mysqlnd_globals)
189
190 #ifdef PHP_DEBUG
191 STD_PHP_INI_ENTRY("mysqlnd.debug_emalloc_fail_threshold","-1", PHP_INI_SYSTEM, OnUpdateLong, debug_emalloc_fail_threshold, zend_mysqlnd_globals, mysqlnd_globals)
192 STD_PHP_INI_ENTRY("mysqlnd.debug_ecalloc_fail_threshold","-1", PHP_INI_SYSTEM, OnUpdateLong, debug_ecalloc_fail_threshold, zend_mysqlnd_globals, mysqlnd_globals)
193 STD_PHP_INI_ENTRY("mysqlnd.debug_erealloc_fail_threshold","-1", PHP_INI_SYSTEM, OnUpdateLong, debug_erealloc_fail_threshold, zend_mysqlnd_globals, mysqlnd_globals)
194
195 STD_PHP_INI_ENTRY("mysqlnd.debug_malloc_fail_threshold","-1", PHP_INI_SYSTEM, OnUpdateLong, debug_malloc_fail_threshold, zend_mysqlnd_globals, mysqlnd_globals)
196 STD_PHP_INI_ENTRY("mysqlnd.debug_calloc_fail_threshold","-1", PHP_INI_SYSTEM, OnUpdateLong, debug_calloc_fail_threshold, zend_mysqlnd_globals, mysqlnd_globals)
197 STD_PHP_INI_ENTRY("mysqlnd.debug_realloc_fail_threshold","-1", PHP_INI_SYSTEM, OnUpdateLong, debug_realloc_fail_threshold, zend_mysqlnd_globals, mysqlnd_globals)
198 #endif
PHP_INI_END()199 PHP_INI_END()
200 /* }}} */
201
202
203 /* {{{ PHP_MINIT_FUNCTION
204 */
205 static PHP_MINIT_FUNCTION(mysqlnd)
206 {
207 REGISTER_INI_ENTRIES();
208
209 mysqlnd_library_init(TSRMLS_C);
210 return SUCCESS;
211 }
212 /* }}} */
213
214
215 /* {{{ PHP_MSHUTDOWN_FUNCTION
216 */
PHP_MSHUTDOWN_FUNCTION(mysqlnd)217 static PHP_MSHUTDOWN_FUNCTION(mysqlnd)
218 {
219 mysqlnd_library_end(TSRMLS_C);
220
221 UNREGISTER_INI_ENTRIES();
222 return SUCCESS;
223 }
224 /* }}} */
225
226
227 #if defined(PHP_DEBUG)
228 /* {{{ PHP_RINIT_FUNCTION
229 */
PHP_RINIT_FUNCTION(mysqlnd)230 static PHP_RINIT_FUNCTION(mysqlnd)
231 {
232 #if defined(PHP_DEBUG)
233 if (MYSQLND_G(debug)) {
234 MYSQLND_DEBUG *dbg = mysqlnd_debug_init(mysqlnd_debug_std_no_trace_funcs TSRMLS_CC);
235 if (!dbg) {
236 return FAILURE;
237 }
238 dbg->m->set_mode(dbg, MYSQLND_G(debug));
239 MYSQLND_G(dbg) = dbg;
240 }
241 #endif
242 return SUCCESS;
243 }
244 /* }}} */
245 #endif
246
247
248 #if defined(PHP_DEBUG)
249 /* {{{ PHP_RSHUTDOWN_FUNCTION
250 */
PHP_RSHUTDOWN_FUNCTION(mysqlnd)251 static PHP_RSHUTDOWN_FUNCTION(mysqlnd)
252 {
253 MYSQLND_DEBUG *dbg = MYSQLND_G(dbg);
254 DBG_ENTER("RSHUTDOWN");
255 if (dbg) {
256 dbg->m->close(dbg);
257 dbg->m->free_handle(dbg);
258 MYSQLND_G(dbg) = NULL;
259 }
260 return SUCCESS;
261 }
262 /* }}} */
263 #endif
264
265
266
267 static const zend_module_dep mysqlnd_deps[] = {
268 ZEND_MOD_REQUIRED("standard")
269 ZEND_MOD_END
270 };
271
272 /* {{{ mysqlnd_module_entry
273 */
274 zend_module_entry mysqlnd_module_entry = {
275 STANDARD_MODULE_HEADER_EX,
276 NULL,
277 mysqlnd_deps,
278 "mysqlnd",
279 mysqlnd_functions,
280 PHP_MINIT(mysqlnd),
281 PHP_MSHUTDOWN(mysqlnd),
282 #if defined(PHP_DEBUG)
283 PHP_RINIT(mysqlnd),
284 #else
285 NULL,
286 #endif
287 #ifdef PHP_DEBUG
288 PHP_RSHUTDOWN(mysqlnd),
289 #else
290 NULL,
291 #endif
292 PHP_MINFO(mysqlnd),
293 MYSQLND_VERSION,
294 PHP_MODULE_GLOBALS(mysqlnd),
295 PHP_GINIT(mysqlnd),
296 NULL,
297 NULL,
298 STANDARD_MODULE_PROPERTIES_EX
299 };
300 /* }}} */
301
302 /* {{{ COMPILE_DL_MYSQLND */
303 #ifdef COMPILE_DL_MYSQLND
304 ZEND_GET_MODULE(mysqlnd)
305 #endif
306 /* }}} */
307
308 /*
309 * Local variables:
310 * tab-width: 4
311 * c-basic-offset: 4
312 * End:
313 * vim600: noet sw=4 ts=4 fdm=marker
314 * vim<600: noet sw=4 ts=4
315 */
316