You can usually use microtime() to get the time at the beginning and end of the page and subtract them. The calculation result is that the page is running The period of time that has elapsed, but this is not necessarily the time that the page itself has been running
The code is as follows | Copy code | ||||||||||||||||||||
//Analysis: Get a time when the page is opened, get a time when loading is completed, and the running time is the difference between the two //1. Custom function
function fn(){ }
'; $t = $end_time-$start_time; echo round($t,2); ?> If you use microtime() to get the start and end times of the page and subtract them, the calculation result is that the page is running The period of time that elapses, but this is not necessarily the time that the page itself was running. Because there may be multiple PHP scripts This page is jointly executed, so I think that method is inaccurate Below I found an example from the Internet about calculating the running time of a page program in PHP. Friends in need can refer to it. I recently wrote a program running time calculation class for your reference:
Look at the simplified program again to calculate page loading time
class runtime { var $StartTime = 0; var $StopTime = 0; function get_microtime() { list($usec, $sec) = explode(' ', microtime()); Return ((float)$usec (float)$sec); } function start() { $this->StartTime = $this->get_microtime(); } function stop() { $this->StopTime = $this->get_microtime(); } function spent() { return round(($this->StopTime - $this->StartTime) * 1000, 1); } } //Instance start http: //www.bkjia.com/PHPjc/629064.html TechArticleYou can usually use microtime() to get the time at the beginning and end of the page and subtract them, the calculation result is The period of time the page takes to run, but this is not necessarily the page itself...
Related labels:
source:php.cn
Previous article:Return value of php function_PHP tutorial
Next article:Detailed introduction to the usage of php bit operations_PHP tutorial
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 Articles by Author
Latest Issues
Group MySQL results by ID for looping over
I have a table with flight data in mysql. I'm writing a php code that will group and displ...
From 2024-04-06 17:27:56
0
1
406
Related Topics
More>
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
|