This article mainly involves thinkphp getting php page execution time, database read/write count, function call count, etc. if you need ThinkPHP, refer to thinkphp
THINKphp has the following effects:
Process: 0.2463 s (Load: 0.0003 s Init: 0.0010 s Exec: 0.1095 s Template: 0.1355 s) | DB: 13 queries 0 writes | Cache: 2 gets, 0 writes | UseMem: 415 kb | LoadFile: 20 | CallFun:
Meaning:
Running Information: the overall execution time is 0.2463 s (loading: 0.0003 s initialization: 0.0010 s execution: 0.1095 s Template: 0.1355 s) | database: 13 read operations, 0 write operations | cache: 2 reads and 0 writes | memory usage: 415 kb | File loading: 20 | function call: 63 (custom), 1370 (built-in)
Next, we will analyze how the data is obtained?
PHP get page Execution time:
The code is 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, and calculate the page execution time to execute this method separately at the beginning and end of the program. The last time difference is the page execution time, and the principle is very simple.
Retrieve Database read/write count
Set a global variable when the database is inserted and read. $ I ++ is executed once every time. This is the db Class method in tp, and the N method is: A method that is automatically accumulated.
Similarly, the cache is calculated in this way.
Memory overhead
Memory_get_usage can be used to obtain the current memory consumption. it can be called at the beginning and end of the program. The difference is the memory overhead.
Number of files loaded
Get_included_files: Gets the names of all files that have been encoded using include, include_once, require or require_once.
That is, you can obtain the number of all include and require files and return the array of imported files:
Official Website example ":
The 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 returned result is:
Abc. php
Test1.php
Test2.php
Test3.php
Test4.php
Function call method
First, let's take a look at this. it seems that it will automatically + 1 when called in each method. however, it is unlikely that every method is not reliable. this group discussed for a long time and finally found a function in php:
Get_defined_functions returns the array format of all methods that introduce the php file, including custom and built-in.
An example of introducing the official website:
The code is as follows:
Function myrow ($ id, $ data)
{
Return"$ Id$ DataN ";
}
$ Arr = get_defined_functions ();
Print_r ($ arr );
?>
The result is:
The 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
...
[1, 750] => bcscale
[751] => bccomp
)
[User] => Array
(
[0] => myrow
)
)
User is the custom method, and internal is the built-in method array.
Extended:
Get_defined_constants: Get the array that defines all constants
Get_defined_functions get the array that defines all functions
Get_defined_vars gets the array that defines all variables
Get_declared_classes returns an array of defined classes.