Skip to content

Instantly share code, notes, and snippets.

@GDmac
Last active December 29, 2015 15:19
Show Gist options
  • Save GDmac/7689850 to your computer and use it in GitHub Desktop.
Save GDmac/7689850 to your computer and use it in GitHub Desktop.
Codeigniter profiler, where are the queries coming from ?
function get_caller_info() {
$c = '';
$file = '';
$line = '';
$func = '';
$class = '';
$trace = debug_backtrace();
if (isset($trace[2])) {
$file = $trace[1]['file'];
$line = $trace[1]['line'];
$func = $trace[2]['function'];
if ((substr($func, 0, 7) == 'include') || (substr($func, 0, 7) == 'require')) {
$func = '';
}
} else if (isset($trace[1])) {
$file = $trace[1]['file'];
$line = $trace[1]['line'];
$func = '';
}
if (isset($trace[3]['class'])) {
$class = $trace[3]['class'];
$func = $trace[3]['function'];
$file = $trace[2]['file'];
$line = $trace[2]['line'];
} else if (isset($trace[2]['class'])) {
$class = $trace[2]['class'];
$func = $trace[2]['function'];
$file = $trace[1]['file'];
$line = $trace[1]['line'];
}
if ($file != ''){
if (strpos($file,BASEPATH)===0) {
$file = 'CI ' . basename($file);
}elseif (strpos($file,APPPATH)===0) {
$file = 'APP ' . basename($file);
}else {
$file = 'UNKNOWN ' . basename($file);
}
}
$c = $file . ": ";
$c .= ($class != '') ? ":" . $class . "->" : "";
$c .= ($func != '') ? $func . "(): " : "";
$c .= ' Line: '.$line;
return($c);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment