PHP mysqli_get_client_stats() Function

Beginner
5 min read
Updated: Nov 2026
3 examples
MySQLi

Definition

In PHP, mysqli_get_client_stats() returns an associative array of client-side performance counters collected by mysqlnd.

It needs the mysqlnd driver. There is no connection parameter—the stats are process-wide for the mysqlnd client. Keys include counts such as bytes sent/received and result set operations (exact keys depend on the mysqlnd build).

Syntax

Call mysqli_get_client_stats() with the values you need. Start with this line.

PHP
$stats = mysqli_get_client_stats();
CallWhat it does
mysqli_get_client_stats()Returns a mysqlnd client statistics array.
$stats["bytes_sent"]Reads one counter from the returned array (key names vary by build).
count(mysqli_get_client_stats())Shows how many statistic keys are available.

Requires mysqlnd. If PHP uses libmysqlclient instead, this function is not available as a useful mysqlnd stats API. Treat the array as diagnostic data, not something to show end users.

Library declarations
PHP
mysqli_get_client_stats(): array

Parameters

ParameterDescription
—This function takes no parameters.

Return Value

Return ValueDescription
arrayAn associative array of mysqlnd client statistics.

PHP Examples

Example 1 — Dump a Few Client Counters

Read mysqlnd client stats and print selected keys from a fixed sample array.

PHP
<?php
$stats = mysqli_get_client_stats();

echo "bytes_sent=", $stats["bytes_sent"], PHP_EOL;
echo "bytes_received=", $stats["bytes_received"], PHP_EOL;

How It Works

  1. mysqli_get_client_stats() returns the mysqlnd array.
  2. Two common keys are printed.
  3. A fresh process may still show zeros in the sample.
  4. After real queries the counters increase.

Example 2 — Count Available Stat Keys

Print how many statistics entries mysqlnd exposed in this sample.

PHP
<?php
$stats = mysqli_get_client_stats();
echo count($stats), PHP_EOL;

How It Works

  1. The function returns one associative array.
  2. count() measures the number of keys.
  3. 62 is a typical sample size; your build may differ.
  4. Use array_keys() if you need the full list.

Example 3 — Stats After a Simple Query

Run one SELECT, then show that bytes_received is non-zero in a sample.

PHP
<?php
$mysqli = mysqli_connect("localhost", "demo", "secret", "shop");
mysqli_query($mysqli, "SELECT 1");
mysqli_close($mysqli);

$stats = mysqli_get_client_stats();
echo "bytes_received=", $stats["bytes_received"], PHP_EOL;

How It Works

  1. A tiny query exercises the client.
  2. The connection is closed afterward.
  3. Client stats still reflect earlier traffic.
  4. The sample bytes_received value is fixed for the tutorial.

Frequently Asked Questions

It returns mysqlnd client statistics as an associative array of counters.
Yes. These stats come from the MySQL Native Driver (mysqlnd).
No connection argument is required. Stats are tracked by the mysqlnd client in the PHP process.
get_client_stats() is process-wide client data. get_connection_stats() reports counters for one connection and needs a mysqli link.
No. They are for developers and operators. Keep them in logs or admin tools.

Next: mysqli_get_client_version()

mysqli_get_client_version() returns the MySQL client library version as an integer. The pr.

mysqli_get_client_version() tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

8 people found this page helpful