Oracle 5.0 Reference Manual page 2655

Table of Contents

Advertisement

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
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]
Mysqlnd replication and load balancing plugin (mysqlnd_ms)
register_shutdown_function
function or the
auto_append_file
2635
PHP

Advertisement

Table of Contents
loading

This manual is also suitable for:

Mysql 5.0

Table of Contents