Find the time to execute a MySQL query through PHP

I saw this question on the Internet ( here and here , for example), but I never saw a good answer. Is it possible to find the time during which a given MySQL query (executed via mysql_query) is accepted through PHP?

It is recommended that you use the php function in some places microtime, but it seems like it might be inaccurate. mysql_querymay get caught up in network latency or a sluggish system that doesn't respond to your request quickly or some other unrelated reason. None of them are directly related to the quality of your request, and this is the only thing I really want to check here. (Please indicate in the comments if you do not agree!)

+3
source share
4 answers

I check only the quality of the request itself, and then remove PHP from the equation. Use a tool like MySQL Query Browser or SQLyog .

Or, if you have shell access, just connect directly. Any of these methods will better determine the actual performance of your queries.

0
source

, . , . , , mysql_query ? , , raw php database (pardon the snark). , PDO:

http://us2.php.net/pdo

, ... ! , ?

+1

If you really need query information, maybe you can use SHOW PROFILES:

http://dev.mysql.com/doc/refman/5.0/en/show-profiles.html

Personally, I would use a combination of microtime-ing, a slow query log, mytop and analyzing problematic queries with the MySQL client (command line).

0
source

All Articles