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: 86 87 98.9 %
Date: 2015-05-21 Functions: 9 9 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /*
       2             :   +----------------------------------------------------------------------+
       3             :   | PHP Version 7                                                        |
       4             :   +----------------------------------------------------------------------+
       5             :   | Copyright (c) 2006-2015 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 "zend_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             : PHPAPI void
      44         142 : mysqlnd_minfo_print_hash(zval *values)
      45             : {
      46             :         zval *values_entry;
      47             :         zend_string     *string_key;
      48             : 
      49       45582 :         ZEND_HASH_FOREACH_STR_KEY_VAL(Z_ARRVAL_P(values), string_key, values_entry) {
      50       22720 :                 convert_to_string(values_entry);
      51       22720 :                 php_info_print_table_row(2, string_key->val, Z_STRVAL_P(values_entry));
      52             :         } ZEND_HASH_FOREACH_END();
      53         142 : }
      54             : /* }}} */
      55             : 
      56             : 
      57             : /* {{{ mysqlnd_minfo_dump_plugin_stats */
      58             : static int
      59         710 : mysqlnd_minfo_dump_plugin_stats(zval *el, void * argument)
      60             : {
      61         710 :         struct st_mysqlnd_plugin_header * plugin_header = (struct st_mysqlnd_plugin_header *)Z_PTR_P(el);
      62         710 :         if (plugin_header->plugin_stats.values) {
      63             :                 char buf[64];
      64             :                 zval values;
      65         142 :                 snprintf(buf, sizeof(buf), "%s statistics", plugin_header->plugin_name);
      66             : 
      67         142 :                 mysqlnd_fill_stats_hash(plugin_header->plugin_stats.values, plugin_header->plugin_stats.names, &values ZEND_FILE_LINE_CC);
      68             : 
      69         142 :                 php_info_print_table_start();
      70         142 :                 php_info_print_table_header(2, buf, "");
      71         142 :                 mysqlnd_minfo_print_hash(&values);
      72         142 :                 php_info_print_table_end();
      73             :                 zval_dtor(&values);
      74             :         }
      75         710 :         return ZEND_HASH_APPLY_KEEP;
      76             : }
      77             : /* }}} */
      78             : 
      79             : 
      80             : /* {{{ mysqlnd_minfo_dump_loaded_plugins */
      81             : static int
      82         710 : mysqlnd_minfo_dump_loaded_plugins(zval *el, void * buf)
      83             : {
      84         710 :         smart_str * buffer = (smart_str *) buf;
      85         710 :         struct st_mysqlnd_plugin_header * plugin_header = (struct st_mysqlnd_plugin_header *)Z_PTR_P(el);
      86         710 :         if (plugin_header->plugin_name) {
      87         710 :                 if (buffer->s) {
      88             :                         smart_str_appendc(buffer, ',');
      89             :                 }
      90         710 :                 smart_str_appends(buffer, plugin_header->plugin_name);
      91             :         }
      92         710 :         return ZEND_HASH_APPLY_KEEP;
      93             : }
      94             : /* }}} */
      95             : 
      96             : 
      97             : /* {{{ mysqlnd_minfo_dump_api_plugins */
      98             : static void
      99         142 : mysqlnd_minfo_dump_api_plugins(smart_str * buffer)
     100             : {
     101         142 :         HashTable *ht = mysqlnd_reverse_api_get_api_list();
     102             :         MYSQLND_REVERSE_API *ext;
     103             : 
     104         710 :         ZEND_HASH_FOREACH_PTR(ht, ext) {
     105         284 :                 if (buffer->s) {
     106             :                         smart_str_appendc(buffer, ',');
     107             :                 }
     108         284 :                 smart_str_appends(buffer, ext->module->name);
     109             :         } ZEND_HASH_FOREACH_END();
     110         142 : }
     111             : /* }}} */
     112             : 
     113             : 
     114             : /* {{{ PHP_MINFO_FUNCTION
     115             :  */
     116         142 : PHP_MINFO_FUNCTION(mysqlnd)
     117             : {
     118             :         char buf[32];
     119             : 
     120         142 :         php_info_print_table_start();
     121         142 :         php_info_print_table_header(2, "mysqlnd", "enabled");
     122         142 :         php_info_print_table_row(2, "Version", mysqlnd_get_client_info());
     123         142 :         php_info_print_table_row(2, "Compression",
     124             : #ifdef MYSQLND_COMPRESSION_ENABLED
     125             :                                                                 "supported");
     126             : #else
     127             :                                                                 "not supported");
     128             : #endif
     129         142 :         php_info_print_table_row(2, "core SSL",
     130             : #ifdef MYSQLND_SSL_SUPPORTED
     131             :                                                                 "supported");
     132             : #else
     133             :                                                                 "not supported");
     134             : #endif
     135         142 :         php_info_print_table_row(2, "extended SSL",
     136             : #ifdef MYSQLND_HAVE_SSL
     137             :                                                                 "supported");
     138             : #else
     139             :                                                                 "not supported");
     140             : #endif
     141         142 :         snprintf(buf, sizeof(buf), ZEND_LONG_FMT, MYSQLND_G(net_cmd_buffer_size));
     142         142 :         php_info_print_table_row(2, "Command buffer size", buf);
     143         142 :         snprintf(buf, sizeof(buf), ZEND_LONG_FMT, MYSQLND_G(net_read_buffer_size));
     144         142 :         php_info_print_table_row(2, "Read buffer size", buf);
     145         142 :         snprintf(buf, sizeof(buf), ZEND_LONG_FMT, MYSQLND_G(net_read_timeout));
     146         142 :         php_info_print_table_row(2, "Read timeout", buf);
     147         142 :         php_info_print_table_row(2, "Collecting statistics", MYSQLND_G(collect_statistics)? "Yes":"No");
     148         142 :         php_info_print_table_row(2, "Collecting memory statistics", MYSQLND_G(collect_memory_statistics)? "Yes":"No");
     149             : 
     150         142 :         php_info_print_table_row(2, "Tracing", MYSQLND_G(debug)? MYSQLND_G(debug):"n/a");
     151             : 
     152             :         /* loaded plugins */
     153             :         {
     154         142 :                 smart_str tmp_str = {0};
     155         142 :                 mysqlnd_plugin_apply_with_argument(mysqlnd_minfo_dump_loaded_plugins, &tmp_str);
     156             :                 smart_str_0(&tmp_str);
     157         142 :                 php_info_print_table_row(2, "Loaded plugins", tmp_str.s? tmp_str.s->val : "");
     158             :                 smart_str_free(&tmp_str);
     159             : 
     160         142 :                 mysqlnd_minfo_dump_api_plugins(&tmp_str);
     161             :                 smart_str_0(&tmp_str);
     162         142 :                 php_info_print_table_row(2, "API Extensions", tmp_str.s? tmp_str.s->val : "");
     163             :                 smart_str_free(&tmp_str);
     164             :         }
     165             : 
     166         142 :         php_info_print_table_end();
     167             : 
     168             : 
     169             :         /* Print client stats */
     170         142 :         mysqlnd_plugin_apply_with_argument(mysqlnd_minfo_dump_plugin_stats, NULL);
     171         142 : }
     172             : /* }}} */
     173             : 
     174             : 
     175             : PHPAPI ZEND_DECLARE_MODULE_GLOBALS(mysqlnd)
     176             : 
     177             : 
     178             : /* {{{ PHP_GINIT_FUNCTION
     179             :  */
     180       20916 : static PHP_GINIT_FUNCTION(mysqlnd)
     181             : {
     182             : #if defined(COMPILE_DL_MYSQLND) && defined(ZTS)
     183             :         ZEND_TSRMLS_CACHE_UPDATE();
     184             : #endif
     185       20916 :         mysqlnd_globals->collect_statistics = TRUE;
     186       20916 :         mysqlnd_globals->collect_memory_statistics = FALSE;
     187       20916 :         mysqlnd_globals->debug = NULL;       /* The actual string */
     188       20916 :         mysqlnd_globals->dbg = NULL; /* The DBG object*/
     189       20916 :         mysqlnd_globals->trace_alloc_settings = NULL;
     190       20916 :         mysqlnd_globals->trace_alloc = NULL;
     191       20916 :         mysqlnd_globals->net_cmd_buffer_size = MYSQLND_NET_CMD_BUFFER_MIN_SIZE;
     192       20916 :         mysqlnd_globals->net_read_buffer_size = 32768;
     193       20916 :         mysqlnd_globals->net_read_timeout = 31536000;
     194       20916 :         mysqlnd_globals->log_mask = 0;
     195       20916 :         mysqlnd_globals->mempool_default_size = 16000;
     196       20916 :         mysqlnd_globals->debug_emalloc_fail_threshold = -1;
     197       20916 :         mysqlnd_globals->debug_ecalloc_fail_threshold = -1;
     198       20916 :         mysqlnd_globals->debug_erealloc_fail_threshold = -1;
     199       20916 :         mysqlnd_globals->debug_malloc_fail_threshold = -1;
     200       20916 :         mysqlnd_globals->debug_calloc_fail_threshold = -1;
     201       20916 :         mysqlnd_globals->debug_realloc_fail_threshold = -1;
     202       20916 :         mysqlnd_globals->sha256_server_public_key = NULL;
     203       20916 :         mysqlnd_globals->fetch_data_copy = FALSE;
     204       20916 : }
     205             : /* }}} */
     206             : 
     207             : 
     208             : /* {{{ PHP_INI_MH
     209             :  */
     210       20916 : static PHP_INI_MH(OnUpdateNetCmdBufferSize)
     211             : {
     212             :         zend_long long_value;
     213             : 
     214       20916 :         ZEND_ATOL(long_value, new_value->val);
     215       20916 :         if (long_value < MYSQLND_NET_CMD_BUFFER_MIN_SIZE) {
     216           0 :                 return FAILURE;
     217             :         }
     218       20916 :         MYSQLND_G(net_cmd_buffer_size) = long_value;
     219             : 
     220       20916 :         return SUCCESS;
     221             : }
     222             : /* }}} */
     223             : 
     224             : 
     225             : /* {{{ PHP_INI_BEGIN
     226             : */
     227             : PHP_INI_BEGIN()
     228             :         STD_PHP_INI_BOOLEAN("mysqlnd.collect_statistics",     "1",  PHP_INI_ALL,    OnUpdateBool,   collect_statistics, zend_mysqlnd_globals, mysqlnd_globals)
     229             :         STD_PHP_INI_BOOLEAN("mysqlnd.collect_memory_statistics","0",PHP_INI_SYSTEM, OnUpdateBool,   collect_memory_statistics, zend_mysqlnd_globals, mysqlnd_globals)
     230             :         STD_PHP_INI_ENTRY("mysqlnd.debug",                                    NULL,   PHP_INI_SYSTEM, OnUpdateString, debug, zend_mysqlnd_globals, mysqlnd_globals)
     231             :         STD_PHP_INI_ENTRY("mysqlnd.trace_alloc",                      NULL,   PHP_INI_SYSTEM, OnUpdateString, trace_alloc_settings, zend_mysqlnd_globals, mysqlnd_globals)
     232             :         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)
     233             :         STD_PHP_INI_ENTRY("mysqlnd.net_read_buffer_size",     "32768",PHP_INI_ALL,  OnUpdateLong,   net_read_buffer_size,   zend_mysqlnd_globals,           mysqlnd_globals)
     234             :         STD_PHP_INI_ENTRY("mysqlnd.net_read_timeout", "31536000",   PHP_INI_SYSTEM, OnUpdateLong,   net_read_timeout, zend_mysqlnd_globals, mysqlnd_globals)
     235             :         STD_PHP_INI_ENTRY("mysqlnd.log_mask",                         "0",  PHP_INI_ALL,    OnUpdateLong,   log_mask, zend_mysqlnd_globals, mysqlnd_globals)
     236             :         STD_PHP_INI_ENTRY("mysqlnd.mempool_default_size","16000",   PHP_INI_ALL,    OnUpdateLong,   mempool_default_size,   zend_mysqlnd_globals,           mysqlnd_globals)
     237             :         STD_PHP_INI_ENTRY("mysqlnd.sha256_server_public_key",NULL,    PHP_INI_PERDIR, OnUpdateString, sha256_server_public_key, zend_mysqlnd_globals, mysqlnd_globals)
     238             :         STD_PHP_INI_BOOLEAN("mysqlnd.fetch_data_copy",        "0",          PHP_INI_ALL,    OnUpdateBool,   fetch_data_copy, zend_mysqlnd_globals, mysqlnd_globals)
     239             : #if PHP_DEBUG
     240             :         STD_PHP_INI_ENTRY("mysqlnd.debug_emalloc_fail_threshold","-1",   PHP_INI_SYSTEM,    OnUpdateLong,   debug_emalloc_fail_threshold,   zend_mysqlnd_globals,           mysqlnd_globals)
     241             :         STD_PHP_INI_ENTRY("mysqlnd.debug_ecalloc_fail_threshold","-1",   PHP_INI_SYSTEM,    OnUpdateLong,   debug_ecalloc_fail_threshold,   zend_mysqlnd_globals,           mysqlnd_globals)
     242             :         STD_PHP_INI_ENTRY("mysqlnd.debug_erealloc_fail_threshold","-1",   PHP_INI_SYSTEM,   OnUpdateLong,   debug_erealloc_fail_threshold,  zend_mysqlnd_globals,           mysqlnd_globals)
     243             : 
     244             :         STD_PHP_INI_ENTRY("mysqlnd.debug_malloc_fail_threshold","-1",   PHP_INI_SYSTEM,     OnUpdateLong,   debug_malloc_fail_threshold,    zend_mysqlnd_globals,           mysqlnd_globals)
     245             :         STD_PHP_INI_ENTRY("mysqlnd.debug_calloc_fail_threshold","-1",   PHP_INI_SYSTEM,     OnUpdateLong,   debug_calloc_fail_threshold,    zend_mysqlnd_globals,           mysqlnd_globals)
     246             :         STD_PHP_INI_ENTRY("mysqlnd.debug_realloc_fail_threshold","-1",   PHP_INI_SYSTEM,    OnUpdateLong,   debug_realloc_fail_threshold,   zend_mysqlnd_globals,           mysqlnd_globals)
     247             : #endif
     248             : PHP_INI_END()
     249             : /* }}} */
     250             : 
     251             : 
     252             : /* {{{ PHP_MINIT_FUNCTION
     253             :  */
     254       20916 : static PHP_MINIT_FUNCTION(mysqlnd)
     255             : {
     256       20916 :         REGISTER_INI_ENTRIES();
     257             : 
     258       20916 :         mysqlnd_library_init();
     259       20916 :         return SUCCESS;
     260             : }
     261             : /* }}} */
     262             : 
     263             : 
     264             : /* {{{ PHP_MSHUTDOWN_FUNCTION
     265             :  */
     266       20952 : static PHP_MSHUTDOWN_FUNCTION(mysqlnd)
     267             : {
     268       20952 :         mysqlnd_library_end();
     269             : 
     270       20952 :         UNREGISTER_INI_ENTRIES();
     271       20952 :         return SUCCESS;
     272             : }
     273             : /* }}} */
     274             : 
     275             : 
     276             : #if PHP_DEBUG
     277             : /* {{{ PHP_RINIT_FUNCTION
     278             :  */
     279             : static PHP_RINIT_FUNCTION(mysqlnd)
     280             : {
     281             :         if (MYSQLND_G(debug)) {
     282             :                 struct st_mysqlnd_plugin_trace_log * trace_log_plugin = mysqlnd_plugin_find("debug_trace");
     283             :                 MYSQLND_G(dbg) = NULL;
     284             :                 if (trace_log_plugin) {
     285             :                         MYSQLND_DEBUG * dbg = trace_log_plugin->methods.trace_instance_init(mysqlnd_debug_std_no_trace_funcs);
     286             :                         MYSQLND_DEBUG * trace_alloc = trace_log_plugin->methods.trace_instance_init(NULL);
     287             :                         if (!dbg || !trace_alloc) {
     288             :                                 return FAILURE;
     289             :                         }
     290             :                         dbg->m->set_mode(dbg, MYSQLND_G(debug));
     291             :                         trace_alloc->m->set_mode(trace_alloc, MYSQLND_G(trace_alloc_settings));
     292             :                         MYSQLND_G(dbg) = dbg;
     293             :                         MYSQLND_G(trace_alloc) = trace_alloc;
     294             :                 }
     295             :         }
     296             :         return SUCCESS;
     297             : }
     298             : /* }}} */
     299             : #endif
     300             : 
     301             : 
     302             : #if PHP_DEBUG
     303             : /* {{{ PHP_RSHUTDOWN_FUNCTION
     304             :  */
     305             : static PHP_RSHUTDOWN_FUNCTION(mysqlnd)
     306             : {
     307             :         MYSQLND_DEBUG * dbg = MYSQLND_G(dbg);
     308             :         MYSQLND_DEBUG * trace_alloc = MYSQLND_G(trace_alloc);
     309             :         DBG_ENTER("RSHUTDOWN");
     310             :         if (dbg) {
     311             :                 dbg->m->close(dbg);
     312             :                 dbg->m->free_handle(dbg);
     313             :                 MYSQLND_G(dbg) = NULL;
     314             :         }
     315             :         if (trace_alloc) {
     316             :                 trace_alloc->m->close(trace_alloc);
     317             :                 trace_alloc->m->free_handle(trace_alloc);
     318             :                 MYSQLND_G(trace_alloc) = NULL;
     319             :         }
     320             :         return SUCCESS;
     321             : }
     322             : /* }}} */
     323             : #endif
     324             : 
     325             : 
     326             : static const zend_module_dep mysqlnd_deps[] = {
     327             :         ZEND_MOD_REQUIRED("standard")
     328             :         ZEND_MOD_END
     329             : };
     330             : 
     331             : /* {{{ mysqlnd_module_entry
     332             :  */
     333             : zend_module_entry mysqlnd_module_entry = {
     334             :         STANDARD_MODULE_HEADER_EX,
     335             :         NULL,
     336             :         mysqlnd_deps,
     337             :         "mysqlnd",
     338             :         mysqlnd_functions,
     339             :         PHP_MINIT(mysqlnd),
     340             :         PHP_MSHUTDOWN(mysqlnd),
     341             : #if PHP_DEBUG
     342             :         PHP_RINIT(mysqlnd),
     343             : #else
     344             :         NULL,
     345             : #endif
     346             : #if PHP_DEBUG
     347             :         PHP_RSHUTDOWN(mysqlnd),
     348             : #else
     349             :         NULL,
     350             : #endif
     351             :         PHP_MINFO(mysqlnd),
     352             :         PHP_MYSQLND_VERSION,
     353             :         PHP_MODULE_GLOBALS(mysqlnd),
     354             :         PHP_GINIT(mysqlnd),
     355             :         NULL,
     356             :         NULL,
     357             :         STANDARD_MODULE_PROPERTIES_EX
     358             : };
     359             : /* }}} */
     360             : 
     361             : /* {{{ COMPILE_DL_MYSQLND */
     362             : #ifdef COMPILE_DL_MYSQLND
     363             : #ifdef ZTS
     364             : ZEND_TSRMLS_CACHE_DEFINE();
     365             : #endif
     366             : ZEND_GET_MODULE(mysqlnd)
     367             : #endif
     368             : /* }}} */
     369             : 
     370             : /*
     371             :  * Local variables:
     372             :  * tab-width: 4
     373             :  * c-basic-offset: 4
     374             :  * End:
     375             :  * vim600: noet sw=4 ts=4 fdm=marker
     376             :  * vim<600: noet sw=4 ts=4
     377             :  */

Generated by: LCOV version 1.10

Generated at Thu, 21 May 2015 19:58:59 +0000 (7 days ago)

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