1--TEST--
2mysqli_get_connection_stats()
3--INI--
4mysqlnd.collect_statistics="1"
5mysqlnd.collect_memory_statistics="1"
6--EXTENSIONS--
7mysqli
8--SKIPIF--
9<?PHP
10require_once 'skipifconnectfailure.inc';
11if (!function_exists('mysqli_get_connection_stats')) {
12    die("skip only available with mysqlnd");
13}
14?>
15--FILE--
16<?php
17    // Use the operations performed in table.inc to create some traffic on the connection
18    // so that we can collect some statistics.
19    require 'table.inc';
20
21    if (!is_array($info = mysqli_get_connection_stats($link)) || empty($info))
22        printf("[003] Expecting array/any_non_empty, got %s/%s\n", gettype($info), $info);
23
24    if (!is_array($info2 = mysqli_get_client_stats()) || empty($info2))
25        printf("[004] Expecting array/any_non_empty, got %s/%s\n", gettype($info2), $info2);
26
27    foreach ($info as $k => &$v) {
28        if (strpos($k, "mem_") === 0) {
29            $v = 0;
30        }
31    }
32    foreach ($info2 as $k => &$v) {
33        if (strpos($k, "mem_") === 0) {
34            $v = 0;
35        }
36    }
37
38    if ($info !== $info2) {
39        printf("[005] The hashes should be identical except of the memory related fields\n");
40        var_dump($info);
41        var_dump($info2);
42    }
43
44    if (!is_array($info = $link->get_connection_stats()) || empty($info))
45        printf("[006] Expecting array/any_non_empty, got %s/%s\n", gettype($info), $info);
46
47    foreach ($info as $k => &$v) {
48        if (strpos($k, "mem_") === 0) {
49            $v = 0;
50        }
51    }
52
53    if ($info !== $info2) {
54        printf("[007] The hashes should be identical except of the memory related fields\n");
55        var_dump($info);
56        var_dump($info2);
57    }
58
59    mysqli_close($link);
60    require 'table.inc';
61
62    if (!is_array($info = mysqli_get_connection_stats($link)) || empty($info))
63        printf("[008] Expecting array/any_non_empty, got %s/%s\n", gettype($info), $info);
64
65    if (!is_array($info2 = mysqli_get_client_stats()) || empty($info2))
66        printf("[009] Expecting array/any_non_empty, got %s/%s\n", gettype($info2), $info2);
67
68    // assuming the test is run in a plain-vanilla CLI environment
69    if ($info === $info2) {
70        printf("[010] The hashes should not be identical\n");
71        var_dump($info);
72        var_dump($info2);
73    }
74
75    print "done!";
76?>
77--CLEAN--
78<?php
79    require_once 'clean_table.inc';
80?>
81--EXPECT--
82done!
83