Get PHP page Execution time, database read and write times, number of function calls (thinkphp) _php Tutorial

Source: Internet
Author: User
Tags time 0
Thinkphp has the effect of debugging running state:

process:0.2463s (load:0.0003s init:0.0010s exec:0.1095s template:0.1355s) | Db:13 Queries 0 writes| Cache:2 gets,0 writes| usemem:415 kb| loadfile:20| callfun:63,1370

Meaning of the Representative:

Run information: Overall execution time 0.2463s (load: 0.0003s initialization: 0.0010s execution: 0.1095s Template: 0.1355s) | Database: 13 reads 0 Write operations | Cache: 2 reads, 0 writes | Using Memory: 415 KB | Loading files: 20 | Function call: 63 (Custom), 1370 (built-in)

Let's analyze how these data are obtained.

PHP Get page Execution time:
Copy CodeThe code is as follows:
/**
* Get current time
*/
function Getmicrotime () {

List ($usec, $sec) = Explode ("", Microtime ());
return (float) $usec + (float) $sec);
}


Use: The above method can get the current time, the calculation of the page execution time can be executed at the beginning and end of the program to execute the method, the last time difference is the page execution, the principle is very simple.

Get database read and write times

When the database is inserted and read, set a global variable, each time the execution succeeds once $i++, this is the method of the DB class in TP, and the method of N is: A method of automatic accumulation.

This is how the same cache is calculated.

Overhead of memory
Memory_get_usage can get the current consumption of memory, can be called at the beginning and end of the program, the difference is the memory cost

Number of loaded files
Get_included_files:gets the names of all files that has been included using include, include_once, require or require_onc E.

That is, the number of files that can be obtained to all Include,require, returning an array of introduced files:

Official Website Example ":

Copy CodeThe code is as follows:
This file is abc.php

Include ' test1.php ';
Include_once ' test2.php ';
Require ' test3.php ';
Require_once ' test4.php ';

$included _files = Get_included_files ();

foreach ($included _files as $filename) {
echo "$filenamen";
}
?>


The results returned are:

abc.php
test1.php
test2.php
test3.php
test4.php

Function Call method
The first one to look at this, the feeling is in each method inside the call automatically +1. But it seems unlikely that each of these methods is not reliable, this group of discussion for half a day, and finally found a function of PHP:

Get_defined_functions returns the array format of all methods that introduce PHP files, including custom, built-in.

An example of introducing the official website:

Copy CodeThe code is as follows:
function Myrow ($id, $data)
{
Return "$id$datan ";
}
$arr = Get_defined_functions ();
Print_r ($arr);
?>


The result is:

Copy CodeThe code is as follows:
Array
(
[internal] = = Array
(
[0] = Zend_version
[1] = Func_num_args
[2] = Func_get_arg
[3] = Func_get_args
[4] = strlen
[5] = strcmp
[6] = strncmp
...
[+] = Bcscale
[751] = Bccomp
)

[User] = Array
(
[0] = Myrow
)
)


User is a custom method, internal is a built-in method array.

Extended:

Get_defined_constants gets an array that defines all the constants
Get_defined_functions gets an array that defines all functions
Get_defined_vars gets an array that defines all the variables
Get_declared_classes returns an array of classes that have already been defined

http://www.bkjia.com/PHPjc/327374.html www.bkjia.com true http://www.bkjia.com/PHPjc/327374.html techarticle thinkphp has the effect of debugging running state: process:0.2463s (load:0.0003s init:0.0010s exec:0.1095s template:0.1355s) | Db:13 Queries 0 writes| Cache:2 gets,0 writes| usemem:415 k ...

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.