Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to show running mysql queries in php

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

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

like image 968
Farshad Avatar asked Jan 22 '23 17:01

Farshad


2 Answers

If the problem is on MySQL site this could help a lot:

mysql_query('show processlist');

It should return all queries waiting for processing. I usually use it directly from mysql console where I don't have to format the output.

like image 50
Petr Peller Avatar answered Jan 25 '23 07:01

Petr Peller


You can rename the original mysql_query function and write your own containing some additional logging/inspecting code to see what is going 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;
}
like image 28
Veger Avatar answered Jan 25 '23 07:01

Veger