Skip to content

Instantly share code, notes, and snippets.

@remcotolsma
Created December 24, 2013 10:41
Show Gist options
  • Save remcotolsma/8111517 to your computer and use it in GitHub Desktop.
Save remcotolsma/8111517 to your computer and use it in GitHub Desktop.
WP Engine database debug file with whitespace after PHP close tag.
<?php
/*
Plugin Name: Wink Bedug Crap
Description: Blah blah
*/
if( isset( $_REQUEST["wpe_check_hooks"] ) ) {
global $wink;
if( empty( $wink ) ) {
//we need to set some starting variables here
$wink = new stdClass();
$wink->start_mem = memory_get_usage() / 1024;
$wink->start_time = microtime(TRUE);
$wink->hooks = array();
$wink->counter = 0;
@ini_set( "eaccelerator.optimizer", 0 );
@eaccelerator_optimizer( false );
declare(ticks = 1);
//register_tick_function( "wink_handler" , true);
}
add_action("wpe_filtered_output","wink_shutdown");
//dump all the data on shutdown
function wink_shutdown($html) {
global $wink;
foreach( $wink->filters as $filter => $action ) {
if( did_action($filter) ) {
$wink->filters[$filter]["HIT"] = did_action($filter);
$count = 0;
if( !empty( $wink->filters[$filter]["info"] ) ) {
foreach( $wink->filters[$filter]["info"] as $priority => $funcs ) {
foreach( $funcs as $fs ) {
$count++;
}
}
}
$wink->filters[$filter]["functions"] = $count;
} else {
unset($wink->filters[$filter]);
}
}
$html = json_encode($wink->filters);
return $html;
}
/*
* This is the primary logging function at this point.
*/
add_filter( "all", "wink_log",10000);
function wink_log( $input ) {
global $wp_filter,$wink;
$this_filter = current_filter();
if( empty( $wp_filter[$this_filter] ) )
return;
if( !array_key_exists($wink->filters[$this_filter]) ) {
$wink->filters[$this_filter] = array(
"time" => array(
"start"=> microtime(TRUE),
),
"memory" => array(
"start"=>memory_get_usage() /1024,
),
"info" => $wp_filter[$this_filter],
);
//figure time sense the last one
$wink->filters[$wink->prev]["time"]["taken"] = microtime(TRUE) - $wink->filters[$wink->prev]["time"]["start"];
$wink->filters[$wink->prev]["memory"]["used"] = (memory_get_usage() /1024) - $wink->filter[$wink->prev]["memory"]["start"];
}
$wink->prev = $this_filter;
return $input;
}
// Still working on this piece
// Ideally to coordinate with the hooks.
function wink_handler() {
global $wink,$wp_filter;
$hook = current_filter();
$func = debug_backtrace();
$caller = array_shift(&$func); //forget the first item cuz it"s our tick handle, but get the immediate caller
//$wink->functions[] = $func;
$wink->current_mem = memory_get_usage() / 1024 ;
//$wink->hooks[$hook]["functions"][] = $func;
$wink->counter++;
}
}?>
// Whitespace mistake!!!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment