# get_caller.php
-
<?php
-
-
function get_caller_info($logFile = "call_info.log"){
-
$callInfos = array();
-
$callFuncs = array();
-
$curTime = date('y-m-d h:i:s',time());
-
$traces = debug_backtrace();
-
$j = 0;
-
$length = count($traces)-1;
-
for ($i = $length; $i >=0; $i--){
-
$trace = $traces[$i];
-
$file = $trace['file'];
-
$line = $trace['line'];
-
$func = $trace['function'];
-
$args = $trace['args'];
-
$argsv = join(",", $args);
-
$tInfo = $curTime." ".$file."(".$line.")->".$func."(".$argsv.")";
-
array_push($callInfos, $tInfo);
-
$tFunc = $file."->".$func."()";
-
array_push($callFuncs, $tFunc);
-
$j++;
-
}
-
-
$callInfoStr = join(";",$callInfos);
-
$callFuncStr = join(";",$callFuncs);
-
$callFuncMd5 = $curTime." ".md5($callFuncStr);
-
file_put_contents($logFile, $callFuncMd5."\n",FILE_APPEND);
-
-
$logFileMd5 = $logFile.".md5";
-
$contMd5 = $callFuncMd5.":".$callInfoStr;
-
file_put_contents($logFileMd5, $contMd5."\n",FILE_APPEND);
-
-
return $callInfos;
-
}
-
-
?>
# test_caller.php
-
<?php
-
require dirname(__FILE__).'/get_caller.php';
-
-
function b($pa,$pb){
-
$t=$pa.$pb;
-
get_caller_info();
-
return $t;
-
}
-
-
function c($pa,$pb,$pc){
-
$t=$pa.$pb.$pc;
-
get_caller_info();
-
return $t;
-
}
-
function a() {
-
b('b1','b2');
-
for ($i = 0; $i <10; $i++){
-
c('c'.$i,'c2','c3');
-
}
-
}
-
-
a();
-
-
?>
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/26250550/viewspace-2127637/
,如需转载,请注明出处,否则将追究法律责任。