Reputation: 3077
I'm having troubles finding a bad query that's really causing high CPU load due to MySQL. I'm looking for a way to have PHP print, at the end of the page, every query that was made after connecting to MySQL. Is there a way to do this without altering the code after every mysql query that already exists? Since there are a lot of include files it's hard to find every query in the script.
I'm aware that I can log every query to a mysql log, but I'm afraid that writing possibly hundreds of queries so fast would overload my server even more. Plus, it's much easier to see all the queries that were made on a particular page, then go through them one at a time.
Thanks in advance.
Upvotes: 2
Views: 300
Reputation: 19403
I always start with the MySQL Slow Query Log - logging each query is going to generate a lot of noise.
If you are using a DAL (you should be) then you could add tracing to the DAL.
Otherwise there isn't an easy way of getting PHP to trace mysql, using php.ini mysql.trace_mode will only warnings and errors.(I've checked the source to php_mysql, function php_mysql_do_query_general
and there isn't anything that will log everything.
Upvotes: 5