Skip to content

Commit

Permalink
Log PHP settings (max_execution_time etc) as early as possible and hi…
Browse files Browse the repository at this point in the history
…ghlight when the values have been altered at runtime
  • Loading branch information
johnbillion committed Apr 10, 2012
1 parent 450c450 commit 8fe1850
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 13 deletions.
47 changes: 35 additions & 12 deletions components/environment.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,32 @@
class QM_Environment extends QM {

var $id = 'environment';
var $php_vars = array(
'max_execution_time',
'memory_limit',
'upload_max_filesize',
'post_max_size'
);

function __construct() {

global $wpdb;

parent::__construct();

add_filter( 'query_monitor_menus', array( $this, 'admin_menu' ), 80 );

# If QueryMonitorDB is in place then we'll use the values which were
# caught early before any plugins had a chance to alter them

foreach ( $this->php_vars as $setting ) {
if ( isset( $wpdb->qm_php_vars[$setting] ) )
$val = $wpdb->qm_php_vars[$setting];
else
$val = ini_get( $setting );
$this->data['php']['variables'][$setting]['before'] = $val;
}

}

function admin_menu( $menu ) {
Expand All @@ -22,7 +44,7 @@ function process() {

global $wp_version, $blog_id;

$vars = array(
$mysql_vars = array(
'key_buffer_size' => true, # Key cache size limit
'max_allowed_packet' => false, # Individual query size limit
'max_connections' => false, # Max number of client connections
Expand All @@ -41,15 +63,15 @@ function process() {

$variables = $db->get_results( "
SHOW VARIABLES
WHERE Variable_name IN ( '" . implode( "', '", array_keys( $vars ) ) . "' )
WHERE Variable_name IN ( '" . implode( "', '", array_keys( $mysql_vars ) ) . "' )
" );

$this->data['db'][$id] = array(
'version' => mysql_get_server_info( $db->dbh ),
'user' => $db->dbuser,
'host' => $db->dbhost,
'name' => $db->dbname,
'vars' => $vars,
'vars' => $mysql_vars,
'variables' => $variables
);

Expand All @@ -76,15 +98,11 @@ function process() {
if ( empty( $php_u ) )
$php_u = '<em>' . __( 'Unknown', 'query-monitor' ) . '</em>';

$this->data['php'] = array(
'version' => phpversion(),
'user' => $php_u,
'variables' => array()
);
$this->data['php']['version'] = phpversion();
$this->data['php']['user'] = $php_u;

# @TODO highlight changes made via ini_set() during runtime (log default values on plugins_loaded)
foreach ( array( 'max_execution_time', 'memory_limit', 'upload_max_filesize', 'post_max_size' ) as $setting )
$this->data['php']['variables'][$setting] = ini_get( $setting );
foreach ( $this->php_vars as $setting )
$this->data['php']['variables'][$setting]['after'] = ini_get( $setting );

$wp_debug = ( WP_DEBUG ) ? 'ON' : 'OFF';

Expand Down Expand Up @@ -128,9 +146,14 @@ function output( $args, $data ) {

foreach ( $data['php']['variables'] as $key => $val ) {

$append = '';

if ( $val['after'] != $val['before'] )
$append .= '<br /><span class="qm-info">' . sprintf( __( 'Overridden from %s', 'query-monitor' ), $val['before'] ) . '</span>';

echo '<tr>';
echo "<td>{$key}</td>";
echo "<td>{$val}</td>";
echo "<td>{$val['after']}{$append}</td>";
echo '</tr>';
}

Expand Down
20 changes: 19 additions & 1 deletion wp-content/db.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php
/*
Plugin Name: Query Monitor
Version: 2.2.1
Version: 2.2.2
Move this file into your wp-content directory to provide additional
database query information in Query Monitor's output.
Expand Down Expand Up @@ -45,6 +45,24 @@ class QueryMonitorDB extends wpdb {
'get_footer'
);
var $qm_filtered = false;
var $qm_php_vars = array(
'max_execution_time' => null,
'memory_limit' => null,
'upload_max_filesize' => null,
'post_max_size' => null
);

/**
* Class constructor
*/
function __construct( $dbuser, $dbpassword, $dbname, $dbhost ) {

foreach ( $this->qm_php_vars as $setting => &$val )
$val = ini_get( $setting );

parent::__construct( $dbuser, $dbpassword, $dbname, $dbhost );

}

/**
* Perform a MySQL database query, using current database connection.
Expand Down

0 comments on commit 8fe1850

Please sign in to comment.