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

Generated by: LCOV version 1.10

Generated at Sat, 22 Nov 2014 23:01:19 +0000 (6 days ago)

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