<?php $before = mysqli_get_client_stats(); if (!is_array($before) || empty($before)) { printf("[001] Expecting non-empty array, got %s.\n", gettype($before)); var_dump($before); } // connect and table inc connect to mysql and create tables require_once 'connect.inc'; $test_table_name = 'test_mysqli_get_client_stats_off_table_1'; require_once 'table.inc'; $after = mysqli_get_client_stats(); if ($before !== $after) { printf("[002] Statistics have changed\n"); var_dump($before); var_dump($after); } foreach ($after as $k => $v) { if ($v != 0) { printf("[003] Field %s should not have any other value but 0, got %s.\n", $k, $v); } } mysqli_close($link); print "done!"; $test_table_name = 'test_mysqli_get_client_stats_off_table_1'; require_once "clean_table.inc";
if (!is_array($info = $link->get_connection_stats()) || empty($info)) { printf("[006] Expecting array/any_non_empty, got %s/%s\n", gettype($info), $info); } foreach ($info as $k => &$v) { if (strpos($k, "mem_") === 0) { $v = 0; } } if ($info !== $info2) { printf("[007] The hashes should be identical except of the memory related fields\n"); var_dump($info); var_dump($info2); } mysqli_close($link); $test_table_name = 'test_mysqli_get_connection_stats_table_1'; require "table.inc"; if (!is_array($info = mysqli_get_connection_stats($link)) || empty($info)) { printf("[008] Expecting array/any_non_empty, got %s/%s\n", gettype($info), $info); } if (!is_array($info2 = mysqli_get_client_stats()) || empty($info2)) { printf("[009] Expecting array/any_non_empty, got %s/%s\n", gettype($info2), $info2); } // assuming the test is run in a plain-vanilla CLI environment if ($info === $info2) { printf("[010] The hashes should not be identical\n"); var_dump($info); var_dump($info2); } print "done!"; $test_table_name = 'test_mysqli_get_connection_stats_table_1'; require_once "clean_table.inc";
mysqli_free_result($res); if (!is_array($new_info = mysqli_get_client_stats()) || empty($new_info)) { printf("[%03d] Expecting array/any_non_empty, got %s/%s\n", ++$test_counter, gettype($new_info), $new_info); } mysqli_get_client_stats_assert_eq('unbuffered_sets', $new_info, (string) ($info['unbuffered_sets'] + 1), $test_counter, 'mysqli_use_result()'); $info = $new_info; if (!($res = mysqli_real_query($link, "SELECT id, label FROM test ORDER BY id"))) { printf("[%03d] Cannot SELECT with mysqli_real_query() II, [%d] %s\n", ++$test_counter, mysqli_errno($link), mysqli_error($link)); } if (!is_object($res = mysqli_store_result($link))) { printf("[%03d] mysqli_use_result() failed, [%d] %s\n", ++$test_counter, mysqli_errno($link), mysqli_error($link)); } while ($row = mysqli_fetch_assoc($res)) { } mysqli_free_result($res); if (!is_array($new_info = mysqli_get_client_stats()) || empty($new_info)) { printf("[%03d] Expecting array/any_non_empty, got %s/%s\n", ++$test_counter, gettype($new_info), $new_info); } mysqli_get_client_stats_assert_eq('buffered_sets', $new_info, (string) ($info['buffered_sets'] + 1), $test_counter, 'mysqli_use_result()'); $info = $new_info; mysqli_close($link); mysqli_get_client_stats_assert_gt('bytes_received_real_data_normal', $info, $expected, $test_counter); $expected['bytes_received_real_data_normal'] = $info['bytes_received_real_data_normal']; mysqli_get_client_stats_assert_eq('bytes_received_real_data_ps', $info, $expected, $test_counter); /* no_index_used bad_index_used flushed_normal_sets flushed_ps_sets explicit_close implicit_close
<?php /** * @author G. Giunta * @copyright (C) G. Giunta 2014-2016 * @license Licensed under GNU General Public License v2.0. See file license.txt */ $mysqlnd_available = false; if (function_exists('mysqli_get_client_stats')) { $stats = mysqli_get_client_stats(); $mysqlnd_available = true; } $tpl->setVariable('stats', $stats); $tpl->setVariable('mysqlnd_available', $mysqlnd_available); $tpl->setVariable('important_stats', array('slow_queries', 'connect_failure'));