Created
April 2, 2012 21:43
-
-
Save xurizaemon/2287449 to your computer and use it in GitHub Desktop.
debugging lengthy node saves
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function nzg_debug_nodeapi(&$node, $op, $teaser = NULL, $page = NULL) { | |
switch ($op) { | |
case 'insert': | |
case 'update': | |
$debug = array( | |
'request' => $_REQUEST, | |
'server' => $_SERVER, | |
'node' => $node, | |
'request time' => $_SERVER['REQUEST_TIME'], | |
'nodeapi time' => time(), | |
); | |
register_shutdown_function('_nzg_node_save_report', $node->nid, $debug); | |
} | |
} | |
function _nzg_node_save_report($nid, $debug) { | |
$debug['shutdown time'] = time(); | |
$debug['processing time'] = $debug['shutdown time'] - $debug['request time']; | |
$filename = '/tmp/nodesave-' . $nid . '-' | |
. $debug['shutdown time'] . '-' | |
. $debug['processing time'] . '.txt'; | |
foreach (array('request time', 'nodeapi time', 'shutdown time') as $v) { | |
$debug[$v] = strtotime($debug[$v]); | |
} | |
file_put_contents($filename, print_r($debug,1)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Did you write this on a train or something? It's far worse than airplane code :-P