Skip to content

Instantly share code, notes, and snippets.

@xurizaemon
Created April 2, 2012 21:43
Show Gist options
  • Save xurizaemon/2287449 to your computer and use it in GitHub Desktop.
Save xurizaemon/2287449 to your computer and use it in GitHub Desktop.
debugging lengthy node saves
<?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));
}
@cafuego
Copy link

cafuego commented Apr 2, 2012

Did you write this on a train or something? It's far worse than airplane code :-P

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment