Home  >  Article  >  Backend Development  >  How to test the slow running of php interface

How to test the slow running of php interface

angryTom
angryTomOriginal
2019-11-01 11:39:173454browse

How to test the slow running of php interface

How to test whether the interface is running slowly in php

To see if our program is running slowly, we need to test the running time. However, the microtime function can analyze program execution time. Here's how to use it.

1. Use the variable $time_start at the beginning of the program to record the time when the program starts running.

<?php
//开始时间
$time_start = microtime(true);

//程序部分

2. Use the variable $time_end at the end of the program to record the program end running time.

//结束时间
$time_end = microtime(true);

3. Finally, use the end time minus the start time to get the program running time. If the time is too long, the interface runs a bit slowly and the program needs to be optimized.

Note: The unit is seconds

//相减得到运行时间
$time = $time_end - $time_start;
echo $time;

4. Test

<?php
$time_start = microtime(true);
// 模拟处理
sleep(3);
$time_end = microtime(true);
$time = $time_end - $time_start;
echo &#39;<br>&#39;, $time, &#39;<br>&#39;;

Result:

3

For more PHP related knowledge, please visit PHP中文网!

The above is the detailed content of How to test the slow running of php interface. For more information, please follow other related articles on the PHP Chinese website!

Statement:
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