Annotation of embedaddon/php/ext/mysqlnd/php_mysqlnd.c, revision 1.1.1.3
1.1 misho 1: /*
2: +----------------------------------------------------------------------+
3: | PHP Version 5 |
4: +----------------------------------------------------------------------+
1.1.1.3 ! misho 5: | Copyright (c) 2006-2013 The PHP Group |
1.1 misho 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: +----------------------------------------------------------------------+
1.1.1.2 misho 15: | Authors: Andrey Hristov <andrey@mysql.com> |
1.1 misho 16: | Ulf Wendel <uwendel@mysql.com> |
1.1.1.2 misho 17: | Georg Richter <georg@mysql.com> |
1.1 misho 18: +----------------------------------------------------------------------+
19: */
20:
1.1.1.2 misho 21: /* $Id$ */
1.1 misho 22: #include "php.h"
23: #include "php_ini.h"
24: #include "mysqlnd.h"
25: #include "mysqlnd_priv.h"
26: #include "mysqlnd_debug.h"
1.1.1.2 misho 27: #include "mysqlnd_statistics.h"
28: #include "mysqlnd_reverse_api.h"
1.1 misho 29: #include "ext/standard/info.h"
1.1.1.2 misho 30: #include "ext/standard/php_smart_str.h"
1.1 misho 31:
32: /* {{{ mysqlnd_functions[]
33: *
34: * Every user visible function must have an entry in mysqlnd_functions[].
35: */
36: static zend_function_entry mysqlnd_functions[] = {
37: PHP_FE_END
38: };
39: /* }}} */
40:
41:
42: /* {{{ mysqlnd_minfo_print_hash */
43: #if MYSQLND_UNICODE
44: PHPAPI void mysqlnd_minfo_print_hash(zval *values)
45: {
46: zval **values_entry;
47: HashPosition pos_values;
48:
49: zend_hash_internal_pointer_reset_ex(Z_ARRVAL_P(values), &pos_values);
50: while (zend_hash_get_current_data_ex(Z_ARRVAL_P(values),
51: (void **)&values_entry, &pos_values) == SUCCESS) {
52: zstr string_key;
53: uint string_key_len;
54: ulong num_key;
55: int s_len;
56: char *s = NULL;
57:
58: TSRMLS_FETCH();
59: zend_hash_get_current_key_ex(Z_ARRVAL_P(values), &string_key, &string_key_len, &num_key, 0, &pos_values);
60:
61: convert_to_string(*values_entry);
62:
63: if (zend_unicode_to_string(ZEND_U_CONVERTER(UG(runtime_encoding_conv)),
64: &s, &s_len, string_key.u, string_key_len TSRMLS_CC) == SUCCESS) {
65: php_info_print_table_row(2, s, Z_STRVAL_PP(values_entry));
66: }
67: if (s) {
68: mnd_efree(s);
69: }
70:
71: zend_hash_move_forward_ex(Z_ARRVAL_P(values), &pos_values);
72: }
73: }
74: #else
75: PHPAPI void mysqlnd_minfo_print_hash(zval *values)
76: {
77: zval **values_entry;
78: HashPosition pos_values;
79:
80: zend_hash_internal_pointer_reset_ex(Z_ARRVAL_P(values), &pos_values);
81: while (zend_hash_get_current_data_ex(Z_ARRVAL_P(values), (void **)&values_entry, &pos_values) == SUCCESS) {
82: char *string_key;
83: uint string_key_len;
84: ulong num_key;
85:
86: zend_hash_get_current_key_ex(Z_ARRVAL_P(values), &string_key, &string_key_len, &num_key, 0, &pos_values);
87:
88: convert_to_string(*values_entry);
89: php_info_print_table_row(2, string_key, Z_STRVAL_PP(values_entry));
90:
91: zend_hash_move_forward_ex(Z_ARRVAL_P(values), &pos_values);
92: }
93: }
94: #endif
95: /* }}} */
96:
97:
1.1.1.2 misho 98: /* {{{ mysqlnd_minfo_dump_plugin_stats */
99: static int
100: mysqlnd_minfo_dump_plugin_stats(void *pDest, void * argument TSRMLS_DC)
101: {
102: struct st_mysqlnd_plugin_header * plugin_header = *(struct st_mysqlnd_plugin_header **) pDest;
103: if (plugin_header->plugin_stats.values) {
104: char buf[64];
105: zval values;
106: snprintf(buf, sizeof(buf), "%s statistics", plugin_header->plugin_name);
107:
108: mysqlnd_fill_stats_hash(plugin_header->plugin_stats.values, plugin_header->plugin_stats.names, &values TSRMLS_CC ZEND_FILE_LINE_CC);
109:
110: php_info_print_table_start();
111: php_info_print_table_header(2, buf, "");
112: mysqlnd_minfo_print_hash(&values);
113: php_info_print_table_end();
114: zval_dtor(&values);
115: }
116: return ZEND_HASH_APPLY_KEEP;
117: }
118: /* }}} */
119:
120:
121: /* {{{ mysqlnd_minfo_dump_loaded_plugins */
122: static int
123: mysqlnd_minfo_dump_loaded_plugins(void *pDest, void * buf TSRMLS_DC)
124: {
125: smart_str * buffer = (smart_str *) buf;
126: struct st_mysqlnd_plugin_header * plugin_header = *(struct st_mysqlnd_plugin_header **) pDest;
127: if (plugin_header->plugin_name) {
128: if (buffer->len) {
129: smart_str_appendc(buffer, ',');
130: }
131: smart_str_appends(buffer, plugin_header->plugin_name);
132: }
133: return ZEND_HASH_APPLY_KEEP;
134: }
135: /* }}} */
136:
137: /* {{{ mysqlnd_minfo_dump_api_plugins */
1.1.1.3 ! misho 138: static void
! 139: mysqlnd_minfo_dump_api_plugins(smart_str * buffer TSRMLS_DC)
1.1.1.2 misho 140: {
1.1.1.3 ! misho 141: HashTable *ht = mysqlnd_reverse_api_get_api_list(TSRMLS_C);
! 142: Bucket *p;
! 143:
! 144: p = ht->pListHead;
! 145: while(p != NULL) {
! 146: MYSQLND_REVERSE_API * ext = *(MYSQLND_REVERSE_API **) p->pData;
! 147: if (buffer->len) {
! 148: smart_str_appendc(buffer, ',');
! 149: }
! 150: smart_str_appends(buffer, ext->module->name);
! 151:
! 152: p = p->pListNext;
1.1.1.2 misho 153: }
154: }
155: /* }}} */
156:
157:
1.1 misho 158: /* {{{ PHP_MINFO_FUNCTION
159: */
160: PHP_MINFO_FUNCTION(mysqlnd)
161: {
162: char buf[32];
163:
164: php_info_print_table_start();
165: php_info_print_table_header(2, "mysqlnd", "enabled");
166: php_info_print_table_row(2, "Version", mysqlnd_get_client_info());
167: php_info_print_table_row(2, "Compression",
168: #ifdef MYSQLND_COMPRESSION_ENABLED
169: "supported");
170: #else
171: "not supported");
172: #endif
173: php_info_print_table_row(2, "SSL",
174: #ifdef MYSQLND_SSL_SUPPORTED
175: "supported");
176: #else
177: "not supported");
178: #endif
179: snprintf(buf, sizeof(buf), "%ld", MYSQLND_G(net_cmd_buffer_size));
180: php_info_print_table_row(2, "Command buffer size", buf);
181: snprintf(buf, sizeof(buf), "%ld", MYSQLND_G(net_read_buffer_size));
182: php_info_print_table_row(2, "Read buffer size", buf);
183: snprintf(buf, sizeof(buf), "%ld", MYSQLND_G(net_read_timeout));
184: php_info_print_table_row(2, "Read timeout", buf);
185: php_info_print_table_row(2, "Collecting statistics", MYSQLND_G(collect_statistics)? "Yes":"No");
186: php_info_print_table_row(2, "Collecting memory statistics", MYSQLND_G(collect_memory_statistics)? "Yes":"No");
187:
188: php_info_print_table_row(2, "Tracing", MYSQLND_G(debug)? MYSQLND_G(debug):"n/a");
189:
1.1.1.2 misho 190: /* loaded plugins */
191: {
192: smart_str tmp_str = {0, 0, 0};
193: mysqlnd_plugin_apply_with_argument(mysqlnd_minfo_dump_loaded_plugins, &tmp_str);
194: smart_str_0(&tmp_str);
195: php_info_print_table_row(2, "Loaded plugins", tmp_str.c);
196: smart_str_free(&tmp_str);
197:
1.1.1.3 ! misho 198: mysqlnd_minfo_dump_api_plugins(&tmp_str TSRMLS_CC);
1.1.1.2 misho 199: smart_str_0(&tmp_str);
200: php_info_print_table_row(2, "API Extensions", tmp_str.c);
201: smart_str_free(&tmp_str);
202: }
1.1 misho 203:
204: php_info_print_table_end();
1.1.1.2 misho 205:
206:
207: /* Print client stats */
208: mysqlnd_plugin_apply_with_argument(mysqlnd_minfo_dump_plugin_stats, NULL);
1.1 misho 209: }
210: /* }}} */
211:
212:
213: PHPAPI ZEND_DECLARE_MODULE_GLOBALS(mysqlnd)
214:
215:
216: /* {{{ PHP_GINIT_FUNCTION
217: */
218: static PHP_GINIT_FUNCTION(mysqlnd)
219: {
220: mysqlnd_globals->collect_statistics = TRUE;
221: mysqlnd_globals->collect_memory_statistics = FALSE;
222: mysqlnd_globals->debug = NULL; /* The actual string */
223: mysqlnd_globals->dbg = NULL; /* The DBG object*/
224: mysqlnd_globals->net_cmd_buffer_size = MYSQLND_NET_CMD_BUFFER_MIN_SIZE;
225: mysqlnd_globals->net_read_buffer_size = 32768;
226: mysqlnd_globals->net_read_timeout = 31536000;
227: mysqlnd_globals->log_mask = 0;
228: mysqlnd_globals->mempool_default_size = 16000;
229: mysqlnd_globals->debug_emalloc_fail_threshold = -1;
230: mysqlnd_globals->debug_ecalloc_fail_threshold = -1;
231: mysqlnd_globals->debug_erealloc_fail_threshold = -1;
232: mysqlnd_globals->debug_malloc_fail_threshold = -1;
233: mysqlnd_globals->debug_calloc_fail_threshold = -1;
234: mysqlnd_globals->debug_realloc_fail_threshold = -1;
235: }
236: /* }}} */
237:
238:
239: static PHP_INI_MH(OnUpdateNetCmdBufferSize)
240: {
241: long long_value = atol(new_value);
242: if (long_value < MYSQLND_NET_CMD_BUFFER_MIN_SIZE) {
243: return FAILURE;
244: }
245: MYSQLND_G(net_cmd_buffer_size) = long_value;
246:
247: return SUCCESS;
248: }
249:
250: /* {{{ PHP_INI_BEGIN
251: */
252: PHP_INI_BEGIN()
253: STD_PHP_INI_BOOLEAN("mysqlnd.collect_statistics", "1", PHP_INI_ALL, OnUpdateBool, collect_statistics, zend_mysqlnd_globals, mysqlnd_globals)
254: STD_PHP_INI_BOOLEAN("mysqlnd.collect_memory_statistics", "0", PHP_INI_SYSTEM, OnUpdateBool, collect_memory_statistics, zend_mysqlnd_globals, mysqlnd_globals)
255: STD_PHP_INI_ENTRY("mysqlnd.debug", NULL, PHP_INI_SYSTEM, OnUpdateString, debug, zend_mysqlnd_globals, mysqlnd_globals)
256: 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)
257: STD_PHP_INI_ENTRY("mysqlnd.net_read_buffer_size", "32768",PHP_INI_ALL, OnUpdateLong, net_read_buffer_size, zend_mysqlnd_globals, mysqlnd_globals)
258: STD_PHP_INI_ENTRY("mysqlnd.net_read_timeout", "31536000", PHP_INI_SYSTEM, OnUpdateLong, net_read_timeout, zend_mysqlnd_globals, mysqlnd_globals)
259: STD_PHP_INI_ENTRY("mysqlnd.log_mask", "0", PHP_INI_ALL, OnUpdateLong, log_mask, zend_mysqlnd_globals, mysqlnd_globals)
260: STD_PHP_INI_ENTRY("mysqlnd.mempool_default_size","16000", PHP_INI_ALL, OnUpdateLong, mempool_default_size, zend_mysqlnd_globals, mysqlnd_globals)
261:
1.1.1.2 misho 262: #if PHP_DEBUG
1.1 misho 263: STD_PHP_INI_ENTRY("mysqlnd.debug_emalloc_fail_threshold","-1", PHP_INI_SYSTEM, OnUpdateLong, debug_emalloc_fail_threshold, zend_mysqlnd_globals, mysqlnd_globals)
264: STD_PHP_INI_ENTRY("mysqlnd.debug_ecalloc_fail_threshold","-1", PHP_INI_SYSTEM, OnUpdateLong, debug_ecalloc_fail_threshold, zend_mysqlnd_globals, mysqlnd_globals)
265: STD_PHP_INI_ENTRY("mysqlnd.debug_erealloc_fail_threshold","-1", PHP_INI_SYSTEM, OnUpdateLong, debug_erealloc_fail_threshold, zend_mysqlnd_globals, mysqlnd_globals)
266:
267: STD_PHP_INI_ENTRY("mysqlnd.debug_malloc_fail_threshold","-1", PHP_INI_SYSTEM, OnUpdateLong, debug_malloc_fail_threshold, zend_mysqlnd_globals, mysqlnd_globals)
268: STD_PHP_INI_ENTRY("mysqlnd.debug_calloc_fail_threshold","-1", PHP_INI_SYSTEM, OnUpdateLong, debug_calloc_fail_threshold, zend_mysqlnd_globals, mysqlnd_globals)
269: STD_PHP_INI_ENTRY("mysqlnd.debug_realloc_fail_threshold","-1", PHP_INI_SYSTEM, OnUpdateLong, debug_realloc_fail_threshold, zend_mysqlnd_globals, mysqlnd_globals)
270: #endif
271: PHP_INI_END()
272: /* }}} */
273:
274:
275: /* {{{ PHP_MINIT_FUNCTION
276: */
277: static PHP_MINIT_FUNCTION(mysqlnd)
278: {
279: REGISTER_INI_ENTRIES();
280:
281: mysqlnd_library_init(TSRMLS_C);
282: return SUCCESS;
283: }
284: /* }}} */
285:
286:
287: /* {{{ PHP_MSHUTDOWN_FUNCTION
288: */
289: static PHP_MSHUTDOWN_FUNCTION(mysqlnd)
290: {
291: mysqlnd_library_end(TSRMLS_C);
292:
293: UNREGISTER_INI_ENTRIES();
294: return SUCCESS;
295: }
296: /* }}} */
297:
298:
1.1.1.2 misho 299: #if PHP_DEBUG
1.1 misho 300: /* {{{ PHP_RINIT_FUNCTION
301: */
302: static PHP_RINIT_FUNCTION(mysqlnd)
303: {
304: if (MYSQLND_G(debug)) {
1.1.1.2 misho 305: struct st_mysqlnd_plugin_trace_log * trace_log_plugin = mysqlnd_plugin_find("debug_trace");
306: MYSQLND_G(dbg) = NULL;
307: if (trace_log_plugin) {
308: MYSQLND_DEBUG * dbg = trace_log_plugin->methods.trace_instance_init(mysqlnd_debug_std_no_trace_funcs TSRMLS_CC);
309: if (!dbg) {
310: return FAILURE;
311: }
312: dbg->m->set_mode(dbg, MYSQLND_G(debug));
313: MYSQLND_G(dbg) = dbg;
1.1 misho 314: }
315: }
316: return SUCCESS;
317: }
318: /* }}} */
319: #endif
320:
321:
1.1.1.2 misho 322: #if PHP_DEBUG
1.1 misho 323: /* {{{ PHP_RSHUTDOWN_FUNCTION
324: */
325: static PHP_RSHUTDOWN_FUNCTION(mysqlnd)
326: {
327: MYSQLND_DEBUG *dbg = MYSQLND_G(dbg);
328: DBG_ENTER("RSHUTDOWN");
329: if (dbg) {
330: dbg->m->close(dbg);
331: dbg->m->free_handle(dbg);
332: MYSQLND_G(dbg) = NULL;
333: }
334: return SUCCESS;
335: }
336: /* }}} */
337: #endif
338:
339:
340:
341: static const zend_module_dep mysqlnd_deps[] = {
342: ZEND_MOD_REQUIRED("standard")
343: ZEND_MOD_END
344: };
345:
346: /* {{{ mysqlnd_module_entry
347: */
348: zend_module_entry mysqlnd_module_entry = {
349: STANDARD_MODULE_HEADER_EX,
350: NULL,
351: mysqlnd_deps,
352: "mysqlnd",
353: mysqlnd_functions,
354: PHP_MINIT(mysqlnd),
355: PHP_MSHUTDOWN(mysqlnd),
1.1.1.2 misho 356: #if PHP_DEBUG
1.1 misho 357: PHP_RINIT(mysqlnd),
358: #else
359: NULL,
360: #endif
1.1.1.2 misho 361: #if PHP_DEBUG
1.1 misho 362: PHP_RSHUTDOWN(mysqlnd),
363: #else
364: NULL,
365: #endif
366: PHP_MINFO(mysqlnd),
367: MYSQLND_VERSION,
368: PHP_MODULE_GLOBALS(mysqlnd),
369: PHP_GINIT(mysqlnd),
370: NULL,
371: NULL,
372: STANDARD_MODULE_PROPERTIES_EX
373: };
374: /* }}} */
375:
376: /* {{{ COMPILE_DL_MYSQLND */
377: #ifdef COMPILE_DL_MYSQLND
378: ZEND_GET_MODULE(mysqlnd)
379: #endif
380: /* }}} */
381:
382: /*
383: * Local variables:
384: * tab-width: 4
385: * c-basic-offset: 4
386: * End:
387: * vim600: noet sw=4 ts=4 fdm=marker
388: * vim<600: noet sw=4 ts=4
389: */
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>