mysqlnd_ms_get_statsReturns query distribution and connection statistics
&reftitle.description;
arraymysqlnd_ms_get_stats
Returns an array of statistics collected by the replication
and load balancing plugin.
The PHP configuration setting
mysqlnd_ms.collect_statistics
controls the collection of statistics. The collection of statistics
is disabled by default for performance reasons.
The scope of the statistics is the
PHP process.
Depending on your deployment model a
PHP process may handle one or multiple requests.
Statistics are aggregated for all connections. It is not possible
to tell how much queries originating from
mysqli,
PDO_MySQL or
mysql API calls have
contributed to the aggregated data values.
&reftitle.parameters;
&no.function.parameters;
&reftitle.returnvalues;
Returns NULL if
the PHP configuration directive
mysqlnd_ms.enable
has disabled the plugin. Otherwise, returns array of statistics.
Array of statistics
StatisticDescriptionVersionuse_slave
The semantics of this statistic has changed between 1.0.1 - 1.1.0.
The meaning for version 1.0.1 is as follows.
Number of statements considered as read-only by the built-in query analyzer.
Neither statements which begin with a SQL hint to force
use of slave nor statements directed to a slave by an user-defined
callback are included. The total number of statements sent to the slaves is
use_slave + use_slave_sql_hint +
use_slave_callback.
PECL/mysqlnd_ms 1.1.0 introduces a new concept of chained filters. The
statictics is now set by the internal load balancing filter. With
version 1.1.0 the load balancing filter is always the last in the
filter chain, if used. In future versions a load balancing filter may be
followed by other filters causing another change in the meaning of
the statistic. If, in the future, a load balancing filter is followed
by another filter it is no longer guaranteed that the satement, whichs
increments use_slave, will be executed on the slaves.
The meaning for version 1.1.0 is as follows. Number of statements
sent to the slaves. Statements directed to a slave by the user filter
(an user-defined callback) are not included. The latter are counted by
use_slave_callback.
Since 1.0.0.use_master
The semantics of this statistic has changed between 1.0.1 - 1.1.0.
The meaning for version 1.0.1 is as follows.
Number of statements not considered as read-only by the built-in query analyzer.
Neither statements which begin with a SQL hint to force
use of master nor statements directed to a master by an user-defined
callback are included. The total number of statements sent to the master is
use_master + use_master_sql_hint +
use_master_callback.
PECL/mysqlnd_ms 1.1.0 introduces a new concept of chained filters. The
statictics is now set by the internal load balancing filter. With
version 1.1.0 the load balancing filter is always the last in the
filter chain, if used. In future versions a load balancing filter may be
followed by other filters causing another change in the meaning of
the statistic. If, in the future, a load balancing filter is followed
by another filter it is no longer guaranteed that the satement, whichs
increments use_master, will be executed on the slaves.
The meaning for version 1.1.0 is as follows. Number of statements
sent to the masters. Statements directed to a master by the user filter
(an user-defined callback) are not included. The latter are counted by
use_master_callback.
Since 1.0.0.use_slave_guess
Number of statements the built-in query analyzer recommends sending to
a slave because they contain no SQL hint to force use of a
certain server. The recommendation may be overruled in the following.
It is not guaranteed whether the statement will be excuted on a slave
or not. This is how often the internal is_select
function has guessed that a slave shall be used. Please, see also the
user space function mysqlnd_ms_query_is_select.
Since 1.1.0.use_master_guess
Number of statements the built-in query analyzer recommends sending to
a master because they contain no SQL hint to force use of a
certain server. The recommendation may be overruled in the following.
It is not guaranteed whether the statement will be excuted on a slave
or not. This is how often the internal is_select
function has guessed that a master shall be used. Please, see also the
user space function mysqlnd_ms_query_is_select.
Since 1.1.0.use_slave_sql_hint
Number of statements sent to a slave because statement begins with
the SQL hint to force use of slave.
Since 1.0.0.use_master_sql_hint
Number of statements sent to a master because statement begins with
the SQL hint to force use of master.
Since 1.0.0.use_last_used_sql_hint
Number of statements sent to server which has run the previous statement,
because statement begins with the SQL hint to force use of previously
used server.
Since 1.0.0.use_slave_callback
Number of statements sent to a slave because an user-defined callback
has chosen a slave server for statement execution.
Since 1.0.0.use_master_callback
Number of statements sent to a master because an user-defined callback
has chosen a master server for statement execution.
Since 1.0.0.non_lazy_connections_slave_success
Number of successfully opened slave connections from
configurations not using
lazy connections.
The total number of successfully opened slave connections
is non_lazy_connections_slave_success +
lazy_connections_slave_successSince 1.0.0.non_lazy_connections_slave_failure
Number of failed slave connection attempts from
configurations not using
lazy connections.
The total number of failed slave connection attempts
is non_lazy_connections_slave_failure +
lazy_connections_slave_failureSince 1.0.0.non_lazy_connections_master_success
Number of successfully opened master connections from
configurations not using
lazy connections.
The total number of successfully opened master connections
is non_lazy_connections_master_success +
lazy_connections_master_successSince 1.0.0.non_lazy_connections_master_failure
Number of failed master connection attempts from
configurations not using
lazy connections.
The total number of failed master connection attempts
is non_lazy_connections_master_failure +
lazy_connections_master_failureSince 1.0.0.lazy_connections_slave_success
Number of successfully opened slave connections from
configurations using
lazy connections.
Since 1.0.0.lazy_connections_slave_failure
Number of failed slave connection attempts from
configurations using
lazy connections.
Since 1.0.0.lazy_connections_master_success
Number of successfully opened master connections from
configurations using
lazy connections.
Since 1.0.0.lazy_connections_master_failure
Number of failed master connection attempts from
configurations using
lazy connections.
Since 1.0.0.trx_autocommit_on
Number of autocommit mode activations via API calls.
This figure may be used to monitor activity related to the plugin configuration
setting
trx_stickiness.
If, for example, you want to know if a certain API call invokes the
mysqlnd library function trx_autocommit(),
which is a requirement for
trx_stickiness,
you may call the user API function in question and check if the
statistic has changed. The statistic is modified only by the
plugins internal subclassed trx_autocommit()
method.
Since 1.0.0.trx_autocommit_off
Number of autocommit mode deactivations via API calls.
Since 1.0.0.trx_master_forced
Number of statemens redirected to the master while
trx_stickiness=master
and autocommit mode is disabled.
Since 1.0.0.
&reftitle.examples;
mysqlnd_ms_get_stats example
]]>
&example.outputs;
string(1) "0"
["use_master"]=>
string(1) "0"
["use_slave_guess"]=>
string(1) "0"
["use_master_guess"]=>
string(1) "0"
["use_slave_sql_hint"]=>
string(1) "0"
["use_master_sql_hint"]=>
string(1) "0"
["use_last_used_sql_hint"]=>
string(1) "0"
["use_slave_callback"]=>
string(1) "0"
["use_master_callback"]=>
string(1) "0"
["non_lazy_connections_slave_success"]=>
string(1) "0"
["non_lazy_connections_slave_failure"]=>
string(1) "0"
["non_lazy_connections_master_success"]=>
string(1) "0"
["non_lazy_connections_master_failure"]=>
string(1) "0"
["lazy_connections_slave_success"]=>
string(1) "0"
["lazy_connections_slave_failure"]=>
string(1) "0"
["lazy_connections_master_success"]=>
string(1) "0"
["lazy_connections_master_failure"]=>
string(1) "0"
["trx_autocommit_on"]=>
string(1) "0"
["trx_autocommit_off"]=>
string(1) "0"
["trx_master_forced"]=>
string(1) "0"
}
]]>
&reftitle.seealso;
Runtime configuration
mysqlnd_ms.collect_statistics
mysqlnd_ms.enable