PHP retrieves the number of database queries that generate a page. Many blog software have such a function. for example, it takes xx milliseconds to generate this page and perform xx database queries. How can this function be implemented? many blog software have such a function, for example, "it takes xx milliseconds to generate this page and perform xx database queries. So how can this function be implemented? let me give you a rough idea.
1. declare global variables in the class constructor
Defines a global variable $ queries to count the number of database queries generated on the page.
function __construct(){parent::__construct();global $queries;}
2. modify the encapsulated query () in the database class ()
You should use the database class to find the method for encapsulating query (), such as the following:
// Execute the SQL statement public function query ($ query) {// echo $ query .'
'; ++ $ GLOBALS ['querys']; return $ this-> result = mysql_query ($ query, $ this-> link );}
Then, each time a Query is executed, the global variable queries will increase by 1.
3. write in the method body as follows:
public function content($id = 0){$GLOBALS['queries'] = 0;// something to doecho $GLOBALS['queries'];}
That is simple to implement.
4. computation of functions executed by PHP scripts
I wrote a blog post about the function used to calculate the execution time of PHP scripts. I will post it here.
// Timing function public function runtime ($ mode = 0) {static $ t; if (! $ Mode) {$ t = microtime (); return ;}$ t1 = microtime (); // list ($ m0, $ s0) = split ("", $ t); list ($ m0, $ s0) = explode ("", $ t); // list ($ m1, $ s1) = split ("", $ t1); list ($ m1, $ s1) = explode ("", $ t1); return sprintf ("%. 3f ms ", ($ s1 + $ m1-$ s0-$ m0) * 1000 );}
Use:
public function content($id = 0){$this -> runtime();$GLOBALS['queries'] = 0;// something to doecho $GLOBALS['queries'];echo $this -> runtime(1);}
Bytes. How can this function be implemented...