Last active
August 29, 2015 14:06
-
-
Save zettamax/7c521d69ff615b21f338 to your computer and use it in GitHub Desktop.
Debug helper
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 | |
declare(ticks=100); | |
register_tick_function('do_profile'); | |
function do_profile() { | |
$bt = debug_backtrace(); | |
if (count($bt) <= 1) { | |
return; | |
} | |
$frame = $bt[1]; | |
unset($bt); | |
$type = $frame['type']; | |
$function = $frame['function']; | |
$class = $frame['class']; | |
$func = function ($a) { | |
if (is_array($a)) { | |
$count = count($a); | |
return "array(...) [$count]"; | |
} elseif (is_string($a)) { | |
if (mb_strlen($a) > 30) { | |
$a = mb_substr($a, 0, 30) . '...'; | |
} | |
return var_export($a, 1); | |
} else { | |
return var_export($a, 1); | |
} | |
}; | |
$args = '(' . implode(', ', array_map($func, $frame['args'])) . ')'; | |
error_log($class . $type . $function . $args . PHP_EOL); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment