PHP  
 PHP: Test and Code Coverage Analysis
downloads | QA | documentation | faq | getting help | mailing lists | reporting bugs | php.net sites | links | my php.net 
 

LCOV - code coverage report
Current view: top level - ext/mysqlnd - php_mysqlnd.c (source / functions) Hit Total Coverage
Test: PHP Code Coverage Lines: 93 94 98.9 %
Date: 2014-10-16 Functions: 9 9 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /*
       2             :   +----------------------------------------------------------------------+
       3             :   | PHP Version 5                                                        |
       4             :   +----------------------------------------------------------------------+
       5             :   | Copyright (c) 2006-2014 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: Andrey Hristov <andrey@mysql.com>                           |
      16             :   |          Ulf Wendel <uwendel@mysql.com>                              |
      17             :   |          Georg Richter <georg@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 "mysqlnd_statistics.h"
      28             : #include "mysqlnd_reverse_api.h"
      29             : #include "ext/standard/info.h"
      30             : #include "ext/standard/php_smart_str.h"
      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         296 : PHPAPI void mysqlnd_minfo_print_hash(zval *values)
      76             : {
      77             :         zval **values_entry;
      78             :         HashPosition pos_values;
      79             : 
      80         296 :         zend_hash_internal_pointer_reset_ex(Z_ARRVAL_P(values), &pos_values);
      81       24568 :         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       23976 :                 zend_hash_get_current_key_ex(Z_ARRVAL_P(values), &string_key, &string_key_len, &num_key, 0, &pos_values);
      87             : 
      88       23976 :                 convert_to_string(*values_entry);
      89       23976 :                 php_info_print_table_row(2, string_key, Z_STRVAL_PP(values_entry));
      90             : 
      91       23976 :                 zend_hash_move_forward_ex(Z_ARRVAL_P(values), &pos_values);
      92             :         }
      93         296 : }
      94             : #endif
      95             : /* }}} */
      96             : 
      97             : 
      98             : /* {{{ mysqlnd_minfo_dump_plugin_stats */
      99             : static int
     100         740 : mysqlnd_minfo_dump_plugin_stats(void *pDest, void * argument TSRMLS_DC)
     101             : {
     102         740 :         struct st_mysqlnd_plugin_header * plugin_header = *(struct st_mysqlnd_plugin_header **) pDest;
     103         740 :         if (plugin_header->plugin_stats.values) {
     104             :                 char buf[64];
     105             :                 zval values;
     106         296 :                 snprintf(buf, sizeof(buf), "%s statistics", plugin_header->plugin_name);
     107             : 
     108         296 :                 mysqlnd_fill_stats_hash(plugin_header->plugin_stats.values, plugin_header->plugin_stats.names, &values TSRMLS_CC ZEND_FILE_LINE_CC); 
     109             : 
     110         296 :                 php_info_print_table_start();
     111         296 :                 php_info_print_table_header(2, buf, "");
     112         296 :                 mysqlnd_minfo_print_hash(&values);
     113         296 :                 php_info_print_table_end();
     114             :                 zval_dtor(&values);
     115             :         }
     116         740 :         return ZEND_HASH_APPLY_KEEP;
     117             : }
     118             : /* }}} */
     119             : 
     120             : 
     121             : /* {{{ mysqlnd_minfo_dump_loaded_plugins */
     122             : static int 
     123         740 : mysqlnd_minfo_dump_loaded_plugins(void *pDest, void * buf TSRMLS_DC)
     124             : {
     125         740 :         smart_str * buffer = (smart_str *) buf;
     126         740 :         struct st_mysqlnd_plugin_header * plugin_header = *(struct st_mysqlnd_plugin_header **) pDest;
     127         740 :         if (plugin_header->plugin_name) {
     128         740 :                 if (buffer->len) {
     129         592 :                         smart_str_appendc(buffer, ',');
     130             :                 }
     131         740 :                 smart_str_appends(buffer, plugin_header->plugin_name);
     132             :         }
     133         740 :         return ZEND_HASH_APPLY_KEEP;
     134             : }
     135             : /* }}} */
     136             : 
     137             : /* {{{ mysqlnd_minfo_dump_api_plugins */
     138             : static void
     139         148 : mysqlnd_minfo_dump_api_plugins(smart_str * buffer TSRMLS_DC)
     140             : {
     141         148 :         HashTable *ht = mysqlnd_reverse_api_get_api_list(TSRMLS_C);
     142             :         Bucket *p;
     143             : 
     144         148 :         p = ht->pListHead;
     145         740 :         while(p != NULL) {
     146         444 :                 MYSQLND_REVERSE_API * ext = *(MYSQLND_REVERSE_API **) p->pData;
     147         444 :                 if (buffer->len) {
     148         296 :                         smart_str_appendc(buffer, ',');
     149             :                 }
     150         444 :                 smart_str_appends(buffer, ext->module->name);
     151             : 
     152         444 :                 p = p->pListNext;
     153             :         }
     154         148 : }
     155             : /* }}} */
     156             : 
     157             : 
     158             : /* {{{ PHP_MINFO_FUNCTION
     159             :  */
     160         148 : PHP_MINFO_FUNCTION(mysqlnd)
     161             : {
     162             :         char buf[32];
     163             : 
     164         148 :         php_info_print_table_start();
     165         148 :         php_info_print_table_header(2, "mysqlnd", "enabled");
     166         148 :         php_info_print_table_row(2, "Version", mysqlnd_get_client_info());
     167         148 :         php_info_print_table_row(2, "Compression",
     168             : #ifdef MYSQLND_COMPRESSION_ENABLED
     169             :                                                                 "supported");
     170             : #else
     171             :                                                                 "not supported");
     172             : #endif
     173         148 :         php_info_print_table_row(2, "SSL",
     174             : #ifdef MYSQLND_SSL_SUPPORTED
     175             :                                                                 "supported");
     176             : #else
     177             :                                                                 "not supported");
     178             : #endif
     179         148 :         snprintf(buf, sizeof(buf), "%ld", MYSQLND_G(net_cmd_buffer_size));
     180         148 :         php_info_print_table_row(2, "Command buffer size", buf);
     181         148 :         snprintf(buf, sizeof(buf), "%ld", MYSQLND_G(net_read_buffer_size));
     182         148 :         php_info_print_table_row(2, "Read buffer size", buf);
     183         148 :         snprintf(buf, sizeof(buf), "%ld", MYSQLND_G(net_read_timeout));
     184         148 :         php_info_print_table_row(2, "Read timeout", buf);
     185         148 :         php_info_print_table_row(2, "Collecting statistics", MYSQLND_G(collect_statistics)? "Yes":"No");
     186         148 :         php_info_print_table_row(2, "Collecting memory statistics", MYSQLND_G(collect_memory_statistics)? "Yes":"No");
     187             : 
     188         148 :         php_info_print_table_row(2, "Tracing", MYSQLND_G(debug)? MYSQLND_G(debug):"n/a");
     189             : 
     190             :         /* loaded plugins */
     191             :         {
     192         148 :                 smart_str tmp_str = {0, 0, 0};
     193         148 :                 mysqlnd_plugin_apply_with_argument(mysqlnd_minfo_dump_loaded_plugins, &tmp_str);
     194         148 :                 smart_str_0(&tmp_str);
     195         148 :                 php_info_print_table_row(2, "Loaded plugins", tmp_str.c);
     196         148 :                 smart_str_free(&tmp_str);
     197             : 
     198         148 :                 mysqlnd_minfo_dump_api_plugins(&tmp_str TSRMLS_CC);
     199         148 :                 smart_str_0(&tmp_str);
     200         148 :                 php_info_print_table_row(2, "API Extensions", tmp_str.c);
     201         148 :                 smart_str_free(&tmp_str);
     202             :         }
     203             : 
     204         148 :         php_info_print_table_end();
     205             : 
     206             : 
     207             :         /* Print client stats */
     208         148 :         mysqlnd_plugin_apply_with_argument(mysqlnd_minfo_dump_plugin_stats, NULL);
     209         148 : }
     210             : /* }}} */
     211             : 
     212             : 
     213             : PHPAPI ZEND_DECLARE_MODULE_GLOBALS(mysqlnd)
     214             : 
     215             : 
     216             : /* {{{ PHP_GINIT_FUNCTION
     217             :  */
     218       20225 : static PHP_GINIT_FUNCTION(mysqlnd)
     219             : {
     220       20225 :         mysqlnd_globals->collect_statistics = TRUE;
     221       20225 :         mysqlnd_globals->collect_memory_statistics = FALSE;
     222       20225 :         mysqlnd_globals->debug = NULL;       /* The actual string */
     223       20225 :         mysqlnd_globals->dbg = NULL; /* The DBG object*/
     224       20225 :         mysqlnd_globals->net_cmd_buffer_size = MYSQLND_NET_CMD_BUFFER_MIN_SIZE;
     225       20225 :         mysqlnd_globals->net_read_buffer_size = 32768;
     226       20225 :         mysqlnd_globals->net_read_timeout = 31536000;
     227       20225 :         mysqlnd_globals->log_mask = 0;
     228       20225 :         mysqlnd_globals->mempool_default_size = 16000;
     229       20225 :         mysqlnd_globals->debug_emalloc_fail_threshold = -1;
     230       20225 :         mysqlnd_globals->debug_ecalloc_fail_threshold = -1;
     231       20225 :         mysqlnd_globals->debug_erealloc_fail_threshold = -1;
     232       20225 :         mysqlnd_globals->debug_malloc_fail_threshold = -1;
     233       20225 :         mysqlnd_globals->debug_calloc_fail_threshold = -1;
     234       20225 :         mysqlnd_globals->debug_realloc_fail_threshold = -1;
     235       20225 : }
     236             : /* }}} */
     237             : 
     238             : 
     239       20225 : static PHP_INI_MH(OnUpdateNetCmdBufferSize)
     240             : {
     241       20225 :         long long_value = atol(new_value);
     242       20225 :         if (long_value < MYSQLND_NET_CMD_BUFFER_MIN_SIZE) {
     243           0 :                 return FAILURE;
     244             :         }
     245       20225 :         MYSQLND_G(net_cmd_buffer_size) = long_value;
     246             : 
     247       20225 :         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             : 
     262             : #if PHP_DEBUG
     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       20225 : static PHP_MINIT_FUNCTION(mysqlnd)
     278             : {
     279       20225 :         REGISTER_INI_ENTRIES();
     280             : 
     281       20225 :         mysqlnd_library_init(TSRMLS_C);
     282       20225 :         return SUCCESS;
     283             : }
     284             : /* }}} */
     285             : 
     286             : 
     287             : /* {{{ PHP_MSHUTDOWN_FUNCTION
     288             :  */
     289       20261 : static PHP_MSHUTDOWN_FUNCTION(mysqlnd)
     290             : {
     291       20261 :         mysqlnd_library_end(TSRMLS_C);
     292             : 
     293       20261 :         UNREGISTER_INI_ENTRIES();
     294       20261 :         return SUCCESS;
     295             : }
     296             : /* }}} */
     297             : 
     298             : 
     299             : #if PHP_DEBUG
     300             : /* {{{ PHP_RINIT_FUNCTION
     301             :  */
     302             : static PHP_RINIT_FUNCTION(mysqlnd)
     303             : {
     304             :         if (MYSQLND_G(debug)) {
     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;
     314             :                 }
     315             :         }
     316             :         return SUCCESS;
     317             : }
     318             : /* }}} */
     319             : #endif
     320             : 
     321             : 
     322             : #if PHP_DEBUG
     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),
     356             : #if PHP_DEBUG
     357             :         PHP_RINIT(mysqlnd),
     358             : #else
     359             :         NULL,
     360             : #endif
     361             : #if PHP_DEBUG
     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             :  */

Generated by: LCOV version 1.10

Generated at Thu, 16 Oct 2014 05:27:04 +0000 (5 days ago)

Copyright © 2005-2014 The PHP Group
All rights reserved.