Home > Backend Development > PHP Tutorial > Performance Monitoring - How to detect how many times a certain PHP method is called in a request, and the time and memory consumption of each time?

Performance Monitoring - How to detect how many times a certain PHP method is called in a request, and the time and memory consumption of each time?

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2023-03-01 19:50:02
Original
1868 people have browsed it

How to detect how many times a certain PHP method is called in a request, and the time and memory consumption of each time?

Reply content:

How to detect how many times a certain method in PHP is called in one request, and the time and memory consumption each time?

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
)
Copy after login

Maybe you need this

Configure xdebug + kcachegrind and it will be fine.

Performance Monitoring - How to detect how many times a certain PHP method is called in a request, and the time and memory consumption of each time?

Related labels:
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Issues
php data acquisition?
From 1970-01-01 08:00:00
0
0
0
PHP extension intl
From 1970-01-01 08:00:00
0
0
0
How to learn php well
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template