Back to index

php5  5.3.10
php_mysqlnd.c
Go to the documentation of this file.
00001 /*
00002   +----------------------------------------------------------------------+
00003   | PHP Version 5                                                        |
00004   +----------------------------------------------------------------------+
00005   | Copyright (c) 2006-2012 The PHP Group                                |
00006   +----------------------------------------------------------------------+
00007   | This source file is subject to version 3.01 of the PHP license,      |
00008   | that is bundled with this package in the file LICENSE, and is        |
00009   | available through the world-wide-web at the following url:           |
00010   | http://www.php.net/license/3_01.txt                                  |
00011   | If you did not receive a copy of the PHP license and are unable to   |
00012   | obtain it through the world-wide-web, please send a note to          |
00013   | license@php.net so we can mail you a copy immediately.               |
00014   +----------------------------------------------------------------------+
00015   | Authors: Georg Richter <georg@mysql.com>                             |
00016   |          Andrey Hristov <andrey@mysql.com>                           |
00017   |          Ulf Wendel <uwendel@mysql.com>                              |
00018   +----------------------------------------------------------------------+
00019 */
00020 
00021 /* $Id: php_mysqlnd.c 321634 2012-01-01 13:15:04Z felipe $ */
00022 #include "php.h"
00023 #include "php_ini.h"
00024 #include "mysqlnd.h"
00025 #include "mysqlnd_priv.h"
00026 #include "mysqlnd_debug.h"
00027 #include "ext/standard/info.h"
00028 
00029 /* {{{ mysqlnd_functions[]
00030  *
00031  * Every user visible function must have an entry in mysqlnd_functions[].
00032  */
00033 static zend_function_entry mysqlnd_functions[] = {
00034        PHP_FE_END
00035 };
00036 /* }}} */
00037 
00038 
00039 /* {{{ mysqlnd_minfo_print_hash */
00040 #if MYSQLND_UNICODE
00041 PHPAPI void mysqlnd_minfo_print_hash(zval *values)
00042 {
00043        zval **values_entry;
00044        HashPosition pos_values;
00045 
00046        zend_hash_internal_pointer_reset_ex(Z_ARRVAL_P(values), &pos_values);
00047        while (zend_hash_get_current_data_ex(Z_ARRVAL_P(values),
00048               (void **)&values_entry, &pos_values) == SUCCESS) {
00049               zstr   string_key;
00050               uint   string_key_len;
00051               ulong  num_key;
00052               int           s_len;
00053               char   *s = NULL;
00054 
00055               TSRMLS_FETCH();
00056               zend_hash_get_current_key_ex(Z_ARRVAL_P(values), &string_key, &string_key_len, &num_key, 0, &pos_values);
00057 
00058               convert_to_string(*values_entry);
00059 
00060               if (zend_unicode_to_string(ZEND_U_CONVERTER(UG(runtime_encoding_conv)),
00061                                                            &s, &s_len, string_key.u, string_key_len TSRMLS_CC) == SUCCESS) {
00062                      php_info_print_table_row(2, s, Z_STRVAL_PP(values_entry));
00063               }
00064               if (s) {
00065                      mnd_efree(s);
00066               }
00067 
00068               zend_hash_move_forward_ex(Z_ARRVAL_P(values), &pos_values);
00069        }
00070 }
00071 #else
00072 PHPAPI void mysqlnd_minfo_print_hash(zval *values)
00073 {
00074        zval **values_entry;
00075        HashPosition pos_values;
00076 
00077        zend_hash_internal_pointer_reset_ex(Z_ARRVAL_P(values), &pos_values);
00078        while (zend_hash_get_current_data_ex(Z_ARRVAL_P(values), (void **)&values_entry, &pos_values) == SUCCESS) {
00079               char   *string_key;
00080               uint   string_key_len;
00081               ulong  num_key;
00082 
00083               zend_hash_get_current_key_ex(Z_ARRVAL_P(values), &string_key, &string_key_len, &num_key, 0, &pos_values);
00084 
00085               convert_to_string(*values_entry);
00086               php_info_print_table_row(2, string_key, Z_STRVAL_PP(values_entry));
00087 
00088               zend_hash_move_forward_ex(Z_ARRVAL_P(values), &pos_values);
00089        }
00090 }
00091 #endif
00092 /* }}} */
00093 
00094 
00095 /* {{{ PHP_MINFO_FUNCTION
00096  */
00097 PHP_MINFO_FUNCTION(mysqlnd)
00098 {
00099        char buf[32];
00100        zval values;
00101 
00102        php_info_print_table_start();
00103        php_info_print_table_header(2, "mysqlnd", "enabled");
00104        php_info_print_table_row(2, "Version", mysqlnd_get_client_info());
00105        php_info_print_table_row(2, "Compression",
00106 #ifdef MYSQLND_COMPRESSION_ENABLED
00107                                                         "supported");
00108 #else
00109                                                         "not supported");
00110 #endif
00111        php_info_print_table_row(2, "SSL",
00112 #ifdef MYSQLND_SSL_SUPPORTED
00113                                                         "supported");
00114 #else
00115                                                         "not supported");
00116 #endif
00117        snprintf(buf, sizeof(buf), "%ld", MYSQLND_G(net_cmd_buffer_size));
00118        php_info_print_table_row(2, "Command buffer size", buf);
00119        snprintf(buf, sizeof(buf), "%ld", MYSQLND_G(net_read_buffer_size));
00120        php_info_print_table_row(2, "Read buffer size", buf);
00121        snprintf(buf, sizeof(buf), "%ld", MYSQLND_G(net_read_timeout));
00122        php_info_print_table_row(2, "Read timeout", buf);
00123        php_info_print_table_row(2, "Collecting statistics", MYSQLND_G(collect_statistics)? "Yes":"No");
00124        php_info_print_table_row(2, "Collecting memory statistics", MYSQLND_G(collect_memory_statistics)? "Yes":"No");
00125 
00126        php_info_print_table_row(2, "Tracing", MYSQLND_G(debug)? MYSQLND_G(debug):"n/a");
00127        php_info_print_table_end();
00128 
00129        /* Print client stats */
00130        php_info_print_table_start();
00131        php_info_print_table_header(2, "Client statistics", "");
00132        mysqlnd_get_client_stats(&values);
00133        mysqlnd_minfo_print_hash(&values);
00134 
00135        zval_dtor(&values);
00136        php_info_print_table_end();
00137 }
00138 /* }}} */
00139 
00140 
00141 PHPAPI ZEND_DECLARE_MODULE_GLOBALS(mysqlnd)
00142 
00143 
00144 /* {{{ PHP_GINIT_FUNCTION
00145  */
00146 static PHP_GINIT_FUNCTION(mysqlnd)
00147 {
00148        mysqlnd_globals->collect_statistics = TRUE;
00149        mysqlnd_globals->collect_memory_statistics = FALSE;
00150        mysqlnd_globals->debug = NULL;     /* The actual string */
00151        mysqlnd_globals->dbg = NULL;       /* The DBG object*/
00152        mysqlnd_globals->net_cmd_buffer_size = MYSQLND_NET_CMD_BUFFER_MIN_SIZE;
00153        mysqlnd_globals->net_read_buffer_size = 32768;
00154        mysqlnd_globals->net_read_timeout = 31536000;
00155        mysqlnd_globals->log_mask = 0;
00156        mysqlnd_globals->mempool_default_size = 16000;
00157        mysqlnd_globals->debug_emalloc_fail_threshold = -1;
00158        mysqlnd_globals->debug_ecalloc_fail_threshold = -1;
00159        mysqlnd_globals->debug_erealloc_fail_threshold = -1;
00160        mysqlnd_globals->debug_malloc_fail_threshold = -1;
00161        mysqlnd_globals->debug_calloc_fail_threshold = -1;
00162        mysqlnd_globals->debug_realloc_fail_threshold = -1;
00163 }
00164 /* }}} */
00165 
00166 
00167 static PHP_INI_MH(OnUpdateNetCmdBufferSize)
00168 {
00169        long long_value = atol(new_value);
00170        if (long_value < MYSQLND_NET_CMD_BUFFER_MIN_SIZE) {
00171               return FAILURE;
00172        }
00173        MYSQLND_G(net_cmd_buffer_size) = long_value;
00174 
00175        return SUCCESS;
00176 }
00177 
00178 /* {{{ PHP_INI_BEGIN
00179 */
00180 PHP_INI_BEGIN()
00181        STD_PHP_INI_BOOLEAN("mysqlnd.collect_statistics",       "1",   PHP_INI_ALL, OnUpdateBool,  collect_statistics, zend_mysqlnd_globals, mysqlnd_globals)
00182        STD_PHP_INI_BOOLEAN("mysqlnd.collect_memory_statistics",       "0",   PHP_INI_SYSTEM, OnUpdateBool,      collect_memory_statistics, zend_mysqlnd_globals, mysqlnd_globals)
00183        STD_PHP_INI_ENTRY("mysqlnd.debug",                             NULL,  PHP_INI_SYSTEM, OnUpdateString,    debug, zend_mysqlnd_globals, mysqlnd_globals)
00184        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)
00185        STD_PHP_INI_ENTRY("mysqlnd.net_read_buffer_size",       "32768",PHP_INI_ALL, OnUpdateLong, net_read_buffer_size,       zend_mysqlnd_globals,              mysqlnd_globals)
00186        STD_PHP_INI_ENTRY("mysqlnd.net_read_timeout",    "31536000",   PHP_INI_SYSTEM, OnUpdateLong,      net_read_timeout, zend_mysqlnd_globals, mysqlnd_globals)
00187        STD_PHP_INI_ENTRY("mysqlnd.log_mask",                          "0",   PHP_INI_ALL,  OnUpdateLong, log_mask, zend_mysqlnd_globals, mysqlnd_globals)
00188        STD_PHP_INI_ENTRY("mysqlnd.mempool_default_size","16000",   PHP_INI_ALL,     OnUpdateLong, mempool_default_size,       zend_mysqlnd_globals,              mysqlnd_globals)
00189 
00190 #ifdef PHP_DEBUG
00191        STD_PHP_INI_ENTRY("mysqlnd.debug_emalloc_fail_threshold","-1",   PHP_INI_SYSTEM,    OnUpdateLong, debug_emalloc_fail_threshold,      zend_mysqlnd_globals,              mysqlnd_globals)
00192        STD_PHP_INI_ENTRY("mysqlnd.debug_ecalloc_fail_threshold","-1",   PHP_INI_SYSTEM,    OnUpdateLong, debug_ecalloc_fail_threshold,      zend_mysqlnd_globals,              mysqlnd_globals)
00193        STD_PHP_INI_ENTRY("mysqlnd.debug_erealloc_fail_threshold","-1",   PHP_INI_SYSTEM,   OnUpdateLong, debug_erealloc_fail_threshold,     zend_mysqlnd_globals,              mysqlnd_globals)
00194 
00195        STD_PHP_INI_ENTRY("mysqlnd.debug_malloc_fail_threshold","-1",   PHP_INI_SYSTEM,     OnUpdateLong, debug_malloc_fail_threshold,       zend_mysqlnd_globals,              mysqlnd_globals)
00196        STD_PHP_INI_ENTRY("mysqlnd.debug_calloc_fail_threshold","-1",   PHP_INI_SYSTEM,     OnUpdateLong, debug_calloc_fail_threshold,       zend_mysqlnd_globals,              mysqlnd_globals)
00197        STD_PHP_INI_ENTRY("mysqlnd.debug_realloc_fail_threshold","-1",   PHP_INI_SYSTEM,    OnUpdateLong, debug_realloc_fail_threshold,      zend_mysqlnd_globals,              mysqlnd_globals)
00198 #endif
00199 PHP_INI_END()
00200 /* }}} */
00201 
00202 
00203 /* {{{ PHP_MINIT_FUNCTION
00204  */
00205 static PHP_MINIT_FUNCTION(mysqlnd)
00206 {
00207        REGISTER_INI_ENTRIES();
00208 
00209        mysqlnd_library_init(TSRMLS_C);
00210        return SUCCESS;
00211 }
00212 /* }}} */
00213 
00214 
00215 /* {{{ PHP_MSHUTDOWN_FUNCTION
00216  */
00217 static PHP_MSHUTDOWN_FUNCTION(mysqlnd)
00218 {
00219        mysqlnd_library_end(TSRMLS_C);
00220 
00221        UNREGISTER_INI_ENTRIES();
00222        return SUCCESS;
00223 }
00224 /* }}} */
00225 
00226 
00227 #if defined(PHP_DEBUG)
00228 /* {{{ PHP_RINIT_FUNCTION
00229  */
00230 static PHP_RINIT_FUNCTION(mysqlnd)
00231 {
00232 #if defined(PHP_DEBUG)
00233        if (MYSQLND_G(debug)) {
00234               MYSQLND_DEBUG *dbg = mysqlnd_debug_init(mysqlnd_debug_std_no_trace_funcs TSRMLS_CC);
00235               if (!dbg) {
00236                      return FAILURE;
00237               }
00238               dbg->m->set_mode(dbg, MYSQLND_G(debug));
00239               MYSQLND_G(dbg) = dbg;
00240        }
00241 #endif
00242        return SUCCESS;
00243 }
00244 /* }}} */
00245 #endif
00246 
00247 
00248 #if defined(PHP_DEBUG)
00249 /* {{{ PHP_RSHUTDOWN_FUNCTION
00250  */
00251 static PHP_RSHUTDOWN_FUNCTION(mysqlnd)
00252 {
00253        MYSQLND_DEBUG *dbg = MYSQLND_G(dbg);
00254        DBG_ENTER("RSHUTDOWN");
00255        if (dbg) {
00256               dbg->m->close(dbg);
00257               dbg->m->free_handle(dbg);
00258               MYSQLND_G(dbg) = NULL;
00259        }
00260        return SUCCESS;
00261 }
00262 /* }}} */
00263 #endif
00264 
00265 
00266 
00267 static const zend_module_dep mysqlnd_deps[] = {
00268        ZEND_MOD_REQUIRED("standard")
00269        ZEND_MOD_END
00270 };
00271 
00272 /* {{{ mysqlnd_module_entry
00273  */
00274 zend_module_entry mysqlnd_module_entry = {
00275        STANDARD_MODULE_HEADER_EX,
00276        NULL,
00277        mysqlnd_deps,
00278        "mysqlnd",
00279        mysqlnd_functions,
00280        PHP_MINIT(mysqlnd),
00281        PHP_MSHUTDOWN(mysqlnd),
00282 #if defined(PHP_DEBUG)
00283        PHP_RINIT(mysqlnd),
00284 #else
00285        NULL,
00286 #endif
00287 #ifdef PHP_DEBUG
00288        PHP_RSHUTDOWN(mysqlnd),
00289 #else
00290        NULL,
00291 #endif
00292        PHP_MINFO(mysqlnd),
00293        MYSQLND_VERSION,
00294        PHP_MODULE_GLOBALS(mysqlnd),
00295        PHP_GINIT(mysqlnd),
00296        NULL,
00297        NULL,
00298        STANDARD_MODULE_PROPERTIES_EX
00299 };
00300 /* }}} */
00301 
00302 /* {{{ COMPILE_DL_MYSQLND */
00303 #ifdef COMPILE_DL_MYSQLND
00304 ZEND_GET_MODULE(mysqlnd)
00305 #endif
00306 /* }}} */
00307 
00308 /*
00309  * Local variables:
00310  * tab-width: 4
00311  * c-basic-offset: 4
00312  * End:
00313  * vim600: noet sw=4 ts=4 fdm=marker
00314  * vim<600: noet sw=4 ts=4
00315  */