debug which wordpress plugin is slower
Once I had a performance problem with wordpress website even if it run on a dedicated server.
I suspected that the problem is one of the plugins but I had at least 50 installed
.
In order to see who’s the slowest I opened wp-includes/plugin.php and temprary changed the do_action function to something like this:
function do_action($tag, $arg = '') { global $wp_filter, $wp_actions, $merged_filters, $wp_current_filter; if ( ! isset($wp_actions) ) $wp_actions = array(); if ( ! isset($wp_actions[$tag]) ) $wp_actions[$tag] = 1; else ++$wp_actions[$tag]; $wp_current_filter[] = $tag; // Do 'all' actions first if ( isset($wp_filter['all']) ) { $all_args = func_get_args(); _wp_call_all_hook($all_args); } if ( !isset($wp_filter[$tag]) ) { array_pop($wp_current_filter); return; } $args = array(); if ( is_array($arg) && 1 == count($arg) && isset($arg[0]) && is_object($arg[0]) ) // array(&$this) $args[] =& $arg[0]; else $args[] = $arg; for ( $a = 2; $a < func_num_args(); $a++ ) $args[] = func_get_arg($a); // Sort if ( !isset( $merged_filters[ $tag ] ) ) { ksort($wp_filter[$tag]); $merged_filters[ $tag ] = true; } reset( $wp_filter[ $tag ] ); do { foreach ( (array) current($wp_filter[$tag]) as $the_ ) { if ( !is_null($the_['function']) ) { if($tag=='init') $time_start = microtime(true); call_user_func_array($the_['function'], array_slice($args, 0, (int) $the_['accepted_args'])); if($tag=='init') { $time_end = microtime(true);$time = $time_end - $time_start; echo print_r($the_['function']).' ----- <b>'.$time."</b><br>\n"; } } } } while ( next($wp_filter[$tag]) !== false ); array_pop($wp_current_filter); }
after this you’ll be able to see what plugin is eating the most of your time (after each function call you’ll see execution time in bold)
It’s not a mature script just a quick snippet to have a starting point for someone who runs into the same problem.