Mysqlnd replication and load balancing plugin (
mysqlnd_ms
)
2635
Statistics are collected on a per PHP process basis. Their scope is a PHP process. Depending on
the PHP deployment model a process may serve one or multiple web requests. If using CGI model, a
PHP process serves one web request. If using FastCGI or pre-fork web server models, a PHP process
usually serves multiple web requests. The same is the case with a threaded web server. Please, note
that threads running in parallel can update the statistics in parallel. Thus, if using a threaded PHP
deployment model, statistics can be changed by more than one script at a time. A script cannot rely on
the fact that it sees only its own changes to statistics.
Example 20.294. Verify plugin activity in a non-threaded deployment model
mysqlnd_ms.enable=1
mysqlnd_ms.collect_statistics=1
<?php
/* Load balanced following "myapp" section rules from the plugins config file (not shown) */
$mysqli = new mysqli("myapp", "username", "password", "database");
if (mysqli_connect_errno())
/* Of course, your error handling is nicer... */
die(sprintf("[%d] %s\n", mysqli_connect_errno(), mysqli_connect_error()));
$stats_before = mysqlnd_ms_get_stats();
if ($res = $mysqli->query("SELECT 'Read request' FROM DUAL")) {
var_dump($res->fetch_all());
}
$stats_after = mysqlnd_ms_get_stats();
if ($stats_after['use_slave'] <= $stats_before['use_slave']) {
echo "According to the statistics the read request has not been run on a slave!";
}
?>
Statistics are aggregated for all plugin activities and all connections handled by the plugin. It is not
possible to tell how much a certain connection handle has contributed to the overall statistics.
Utilizing PHPs
register_shutdown_function
function or the
auto_append_file
PHP
configuration directive it is easily possible to dump statistics into, for example, a log file when a script
finishes. Instead of using a log file it is also possible to send the statistics to an external monitoring tool
for recording and display.
Example 20.295. Recording statistics during shutdown
mysqlnd_ms.enable=1
mysqlnd_ms.collect_statistics=1
error_log=/tmp/php_errors.log
<?php
function check_stats() {
$msg = str_repeat("-", 80) . "\n";
$msg .= var_export(mysqlnd_ms_get_stats(), true) . "\n";
$msg .= str_repeat("-", 80) . "\n";
error_log($msg);
}
register_shutdown_function("check_stats");
?>
20.7.6.7. Predefined Constants
Copyright 1997-2012 the PHP Documentation Group. [2230]
Summary of Contents for 5.0
Page 1: ...MySQL 5 0 Reference Manual ...
Page 18: ...xviii ...
Page 60: ...40 ...
Page 396: ...376 ...
Page 578: ...558 ...
Page 636: ...616 ...
Page 844: ...824 ...
Page 1234: ...1214 ...
Page 1427: ...MySQL Proxy Scripting 1407 ...
Page 1734: ...1714 ...
Page 1752: ...1732 ...
Page 1783: ...Configuring Connector ODBC 1763 ...
Page 1793: ...Connector ODBC Examples 1773 ...
Page 1839: ...Connector Net Installation 1819 2 You must choose the type of installation to perform ...
Page 2850: ...2830 ...
Page 2854: ...2834 ...
Page 2928: ...2908 ...
Page 3000: ...2980 ...
Page 3122: ...3102 ...
Page 3126: ...3106 ...
Page 3174: ...3154 ...
Page 3232: ...3212 ...