Get PHP page Execution time, database read and write times, function call times (thinkphp) _php tips

Source: Internet
Author: User
Tags current time 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

The meaning of the representative:

Running information: Overall execution time 0.2463s (load: 0.0003s initialization: 0.0010s execution: 0.1095s Template: 0.1355s) | Database: 13 times read Operation 0 Times write operation | Cache: 2 reads, 0 writes | Using Memory: 415 KB | Loaded files: 20 | Function call: 63 (Custom), 1370 (built-in)

Let's analyze how these data are obtained.

PHP gets page Execution time:
Copy Code code as follows:

/**
* Get the 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 page execution time can be at the beginning of the program and the end of the implementation of the method, the last time difference is the page execution, the principle is very simple.

Get database read and write times

Set a global variable at the time the database is inserted and read, $i++ once for each successful execution, , this is the method of DB class in TP, and the method of N is: One method of automatic accumulation.

This is how the same cache is calculated.

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

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

That is, the number of files that can be fetched to all include,require, which returns an array of imported files:

Official Website Example ":

Copy Code code as follows:

<?php
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 result returned is:

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

Function Call method
The first one to look at this, it feels like it's automatically +1 when invoked inside each method. But it's not likely, it seems, that every method is written in a way that's a long discussion, and finally a function of PHP is found:

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

An example of the introduction of the official website:

Copy Code code as follows:

<?php
function Myrow ($id, $data)
{
Return "<tr><th> $id </th><td> $data </td></tr>n";
}
$arr = Get_defined_functions ();
Print_r ($arr);
?>


The result:

Copy Code code 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
...
[750] => Bcscale
[751] => Bccomp
)

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


User is the custom method, internal is an array of built-in methods.

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 been defined

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.