PHP获取接口请求时间封装方法
public static function changeTimeType(){
// 结束的时钟时间(秒)
$huafei_time_end = microtime(true);
// 计算脚本执行时间
$seconds = ($huafei_time_end - LARAVEL_START);
if ($seconds > 3600) {
$hours = intval($seconds / 3600);
$minutes = $seconds % 3600;
$time = $hours . "小时" . gmstrftime('%M分钟%S秒', $minutes);
} else {
$time = $seconds . '秒';
}
//分配给PHP的总内存
$neicun_zong = memory_get_usage(true);
$neicun_zong_kb= $neicun_zong / 1024;
$neicun_zong_out = $neicun_zong_kb . ' ' . 'KB';
$neicun_zong_mb= 0;
if ($neicun_zong_kb > 10240) {
$neicun_zong_mb= $neicun_zong_kb / 1024;
$neicun_zong_out = $neicun_zong_mb . ' ' . 'MB';
}
if ($neicun_zong_mb > 10240) {
$neicun_zong_gb= $neicun_zong_mb / 1024;
$neicun_zong_out = $neicun_zong_gb . ' ' . 'GB';
}
//PHP实际使用的内存
$neicun_yong = memory_get_usage(false);
$neicun_yong_kb= $neicun_yong / 1024;
$neicun_yong_out = $neicun_yong_kb . ' ' . 'KB';
if ($neicun_yong_kb > 10240) {
$neicun_yong_mb= $neicun_yong_kb / 1024;
$neicun_yong_out = $neicun_yong_mb . ' ' . 'MB';
}
if ($neicun_yong_mb > 10240) {
$neicun_yong_gb= $neicun_yong_mb / 1024;
$neicun_yong_out = $neicun_yong_gb . ' ' . 'GB';
}
$action = request()->route()->uri();
if ($action!='t') {
addLog('PHP(' . $action . ')耗时「' . $time . '」');
}
} 有用, mark了 可以,试试去
页:
[1]