The MySQL Enterprise Plugin for Connector/PHP lets you use the Query Analyzer to monitor MySQL queries from PHP applications, such as PHP-enabled web pages. As described in Section 21.3, “Query Analyzer User Interface”, the Query Analyzer can help you locate queries that are inefficient or slow. Tuning such queries helps to shorten load times for web pages, and improves overall system responsiveness and scalability.
The Aggregator is not yet available with MySQL Enterprise Monitor 3.0.
The PHP query data is routed through the aggregator component of MySQL Enterprise Monitor Agent. Because PHP processes are typically short-lived, the Aggregator receives bursts of query information from the PHP plugin, aggregates and computes statistics, and periodically sends this data to the MySQL Enterprise Service Manager, where it is displayed on the Query Analyzer tab. You must have the MySQL Enterprise Agent Aggregator enabled and running to use Query Analyzer with PHP applications.
Table 21.5. MySQL Enterprise Plugin for Connector/PHP Summary
The MySQL Enterprise Plugin for Connector/PHP requires PHP 5.3.2 or above, with the MySQL
mysqlnd, installed. This is the
recommended configuration. If your PHP installation was not
configured with the
mysqlnd enabled, you must
rebuild and install PHP from source using at least one of the
The preceding options are supplied to the
configure command, depending on which extension
you are using (
PDO_MYSQL). If you use more than one
extension, provide multiple options. Specifying any of the options
listed rebuilds PHP with
mysqlnd support. You
also must enable the PHP JSON module.
For further information on MySQL Native Driver
MySQL Native Driver (
The MySQL client application user, that makes PHP connections in
your PHP code, must have
SELECT privileges on the
mysql.inventory table. This table contains the
server UUID; it is required to
report the Query Analyzer data to the MySQL Enterprise Service Manager. Use the
GRANT statement. For example:
mysql> GRANT SELECT on mysql.inventory to '
user'@'localhost' IDENTIFIED BY '
The plugin is provided as a regular PHP module (PHP extension), and installation follows those PHP standard procedures as described on http://php.net/install.pecl.
Download the MySQL Enterprise Plugin for Connector/PHP, then use the following step-by-step instructions to install and configure the MySQL Enterprise Plugin for Connector/PHP extension.
php.ini configuration file. If
you do not know the location, you can view information about
your PHP installation by creating a script containing:
<?php phpinfo(); ?>
Place the script within a directory configured for providing PHP web pages. Now load the page in your web browser to see a list of configuration and other information about your PHP installation.
Check the output for Loaded Configuration
File. If the value is
refer to the Configuration File (php.ini)
Path and create a file called
php.ini in there. If a Scan this
dir for additional .ini files option is listed you
can also create a file using any name you like, ending
.ini, in that directory to set
Identify whether or not your PHP build was built “thread
safe” by checking the Thread Safety
value in the output from the
If your PHP build is thread safe, you need
mysqlenterprise_ts.so on Linux, Unix, and
OS X, or
Microsoft Windows. If not, use
mysqlenterprise.so on Linux, Unix, and OS
php_mysqlenterprise.dll on Microsoft
Add an entry for the MySQL Enterprise Plugin for Connector/PHP module. You can use the full path:
Alternatively, put the file into the directory identified by
extension_dir configuration option, and
specify just the filename:
mysqlnd is loaded as a shared library
mysqlnd.so), then it
must be loaded before
mysqlenterprise.so as otherwise an error
such as "PHP Warning: PHP Startup: Unable to load dynamic
library '/mysqlenterprise.so' - /mysqlenterprise.so: undefined
symbol: mysqlnd_plugin_register in Unknown on line 0" will be
emitted by PHP. Either:
php.ini is used to load the PHP
extensions, then list it first. For example:
If individual ini files are used to load the PHP
extensions, then note that the ini files are loaded
alphabetically, so adjust accordingly so that
mysqlnd.so is loaded first. For
/etc/php.d/ might contain:
Users of Debian-based systems, such as Ubuntu, are encouraged to
php5enmod command to enable
extensions. For example:
$ php5enmod /path/to/mysqlenterprise.so
php5enmod creates a symlink from the usual
conf.d directory that points to where the
real files are located in
and prefixes it with a priority number.
Restart your Web server application to reload PHP and the configured extensions.
Now reload the
phpinfo() page that you
created earlier, and inspect the listing for the
If you are using PHP on Microsoft Windows with the Apache web server (httpd) built from apache.org, note the following.
Historically, the Win32 Apache web server binary from apache.org is compiled with the legacy Microsoft Visual Studio 6 compiler (VC6). MySQL no longer supports VC6, and as a consequence the MySQL Enterprise Plugin for Connector/PHP for Microsoft Windows is compiled with the newer VC9 compiler. You can not use PHP as a loaded module with an Apache web server build that uses VC6. Alternative Apache builds exist that use VC9, so check your source and be sure that your binaries are both compiled using VC9. Or, instead of loading PHP as a module, you can run PHP in (Fast)CGI mode. See http://windows.fyicenter.com/view.php?ID=68&R=71 for configuration details.
Note that PHP binaries for Microsoft Windows from php.net have
mysqlnd support by default, since
The configuration of the MySQL Enterprise Plugin for Connector/PHP is handled through the
standard PHP configuration files, either globally using
php.ini, or by using the per-directory options,
as detailed in PHP
Configuration. The following table shows the available
Each PHP configuration option for MySQL Enterprise Monitor is prefixed by
Table 21.6. MySQL Enterprise Plugin for Connector/PHP Options
|Property Name||Property Type||Default|
The following list describes these options in more detail:
A boolean value specifying whether query analysis should be enabled.
A string specifying the hostname and port for the MySQL Enterprise Agent Aggregator.
The user name for communicating with the MySQL Enterprise Agent Aggregator. This is defined in the MySQL Enterprise Monitor User Interface, and is assigned the Agent role.
This will only have an effect if the password (mysqlenterprise.aggregator_password) is also set.
The password for communicating with the MySQL Enterprise Agent Aggregator. This is defined in the MySQL Enterprise Monitor User Interface.
This will only have an effect if the user (mysqlenterprise.aggregator_user) is also set.
Timeout in seconds when communicating with the MySQL Enterprise Agent Aggregator.
The microseconds part of the timeout when communicating with the MySQL Enterprise Agent Aggregator.
Whether a backtrace will be generated. A backtrace is helpful while locating the source of errors, but it will have a performance impact.
Name of the callback function to be invoked whenever data is sent to the agent. This callback is defined in the PHP application, and is a PHP function that requires one parameter. This parameter is an array of HTTP requests made to the aggregator.
This should only be set while debugging MySQL Enterprise Monitor, and likely only used when support personal asks for it and defines how you should use this configuration option.
Opens a file to log all the Query Analyzer information sent to MySQL Enterprise Agent Aggregator while monitoring queries.
This should only be enabled while debugging MySQL Enterprise Monitor because it will log every request, which may result in a large log file.
For example, you might configure your
file with the following options:
extension = /usr/local/apache/php/lib/php/extensions/mysqlenterprise.so mysqlenterprise.aggregator_url = tcp://aggregator:14000 mysqlenterprise.quan_enabled = 1 mysqlenterprise.debug_callback = cta_callback mysqlenterprise.disable_backtrace = 1 mysqlenterprise.aggregator_user = username mysqlenterprise.aggregator_password = "password"
The Aggregator-related options must be set, as MySQL Enterprise Plugin for Connector/PHP cannot function without a connection to the Aggregator.
Restart your web server for the configuration options to take
effect. Verify your desired settings are in effect by checking the
output of the
phpinfo() PHP function.
After you set up MySQL Enterprise Plugin for Connector/PHP, you monitor the performance of your PHP applications through the Query Analyzer tab, as described in Section 21.3, “Query Analyzer User Interface”.
When the MySQL Enterprise Plugin for Connector/PHP connects to a MySQL server, it must be
able to retrieve the UUID of that
server. If there is a problem, for example if the
mysql.inventory table does not exist or the MySQL
user does not have privileges to read it, the problem is reported
using the standard PHP error reporting mechanism. PHP classifies
such a problem as an
E_WARNING. Depending on how
you have configured PHP error reporting, the associated messages
might be displayed as part of the application output, stored in a
PHP error log file, or discarded. For specific details about PHP
error reporting, see http://php.net/errorfunc.
In PHP, the
error_log PHP directive defines the
location of the PHP error log, and its usage requires that the
log_errors PHP directive is enabled.