性能监控 - 如何检测PHP某个方法 在一次请求中调用了多少次,每次的耗时和耗内存情况?

查看:95
本文介绍了性能监控 - 如何检测PHP某个方法 在一次请求中调用了多少次,每次的耗时和耗内存情况?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问 题

如何检测PHP某个方法 在一次请求中调用了多少次,每次的耗时和耗内存情况?

解决方案

function  microtime_float ()
{
    list( $usec ,  $sec ) =  explode ( " " ,  microtime ());
    return ((float) $usec  + (float) $sec );
}

  function test(){
     static $num = 0;
     $num ++;
     $memory =  memory_get_usage () ;
     $time_start  =  microtime_float ();
     // 操作过程略
     usleep ( 100 );
     $m = memory_get_usage () -$memory;//内存
     $t =  microtime_float () -$time_start;//耗时
     return [$num,$m,$t];
}
test();
test();
print_r(test());
Array
(
    [0] => 3
    [1] => 0
    [2] => 0.00016498565673828
)

这篇关于性能监控 - 如何检测PHP某个方法 在一次请求中调用了多少次,每次的耗时和耗内存情况?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆