Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how do you show page load time in php?

What is the code to show how long it took for PHP to process a page?

Also, how many sql queries were performed to generate that page?

like image 967
bigsurf Avatar asked Dec 14 '22 03:12

bigsurf


1 Answers

For the first question.

$start = microtime(true);
$end = microtime(true);

printf("Page was generated in %f seconds", $end - $start);

The second one is a little more complicated. You need an shared gateways that keeps tracks of all your queries and stores an execution counter. The most simple example can be a wrapper method around the mysql_query that increments a static variable and then passes the query to mysql_query.

The most part of modern ORM implements that feature, if you already use one of them.

like image 184
Simone Carletti Avatar answered Dec 26 '22 13:12

Simone Carletti