How to show running mysql queries in php

I have a memory overflow problem and I need to scan all my scripts.

My question is, how can I show a list of running mysql queries in php?

+4
source share
5 answers

If the problem is with the MySQL site, this can help a lot:

mysql_query('show processlist'); 

It should return all requests pending. I usually use it directly from the mysql console, where I do not need to format the output.

+4
source

You can rename the original mysql_query function and write your own containing additional logging / verification code to find out what is wrong with your queries:

 rename_function('mysql_query', 'mysql_query_original'); override_function('mysql_query', '$query', 'return mysql_query_override($query);'); function mysql_query_override($query){ echo "Query started"; // Add some more sensible information here $result = mysql_query_original($query); echo "Query ended"; // Add some more sensible information here return $result; } 
+3
source

If you do not use a site with a massive level of traffic, then any snapshot of requests launched / completed is unlikely to be representative. There are also problems in terms of correlating the request with the script that spawned it.

I would recommend using your own code - use auto-prepend to define a wrapper around mysql_query() , then you can implement your own log, which:

  • creates a log entry before running the script (most log entries are created later - not very convenient if the code that writes the failure log)
  • writes the script that caused the request and the request itself
  • records memory usage before
  • records the same facts after time

Then do a recursive search and replace the source code to replace the mysql_query() calls with your wrapper function.

+2
source

I suggest you connect to the database server and run show full processlist; This will show you all the active requests, and you can debug from there. In addition, it would be useful to add some tools for your project to record slow requests.

0
source

Only one request is executed at any given time, since it works PHP, it does not make asynchronous. If you do not use some third-party library to do it differently.

* EDIT: It seems perhaps possible to take a look at: Asynchronous PHP calls? . However, when you run PHP to run async, there is still no way to find out how many requests are being executed. Perhaps you can try and check out some mysql statistics while your code is running.

-one
source

All Articles