How to get trace of all database queries executed by php

php.internals

Raja Kulasekaran

10 years ago
Hi, Sorry If I am asking this question in irrelevent forum. Please suggest me the point of direction if not. I have encrypted php Application codebase which I may or may not have access. So, I would like to know how the application behaving / profiling Database queries through the .so or .dll level . Is there any php extension available which help me out to give the statistics of all the queries execution details ? Thanks, Raja K

Stas Malyshev

10 years ago
Hi!
> Is there any php extension available which help me out to give the > statistics of > all the queries execution details ?
I'm not sure there is an extension doing specifically that, but any profiler or debugger extension would be able to capture database calls, and thus have access to this data. They usually would not dump this information though, so one would need to modify them to do it. Also, you may have better luck just enabling query logging in your database, most databases allow to do that.
-- Stas Malyshev smalyshev@gmail.com

Yasuo Ohgaki

10 years ago
Hi, On Sat, May 7, 2016 at 9:06 AM, Stanislav Malyshev <smalyshev@gmail.com> wrote:
> >> Is there any php extension available which help me out to give the >> statistics of >> all the queries execution details ? > > I'm not sure there is an extension doing specifically that, but any > profiler or debugger extension would be able to capture database calls, > and thus have access to this data. They usually would not dump this > information though, so one would need to modify them to do it. Also, you > may have better luck just enabling query logging in your database, most > databases allow to do that.
I would like to write one from years ago. It is not started yet, though. We need such extension because database level logging is useless without account information. If anyone need it now, you may use RunKit for this purpose. http://php.net/manual/en/book.runkit.php Replace query execution function/method with your version and log whatever you need. Regards,
-- Yasuo Ohgaki yohgaki@ohgaki.net

Walter Parker

10 years ago
On Fri, May 6, 2016 at 4:34 PM, Raja Kulasekaran <cullsin@gmail.com> wrote:
> Hi, > > Sorry If I am asking this question in irrelevent forum. > Please suggest me the point of direction if not. > > I have encrypted php Application codebase which I may or may not have > access. > > So, I would like to know how the application behaving / profiling Database > queries through the .so or .dll level . > > Is there any php extension available which help me out to give the > statistics of > all the queries execution details ? > > Thanks, > Raja K >
This is not really the right list. However, you might look at turning on SQL query logging/statistics on the DB server side. The DB should be able to give you stats and feel for the query profiles. This would be a lot less work than adding shims to the plugins. Walter
-- The greatest dangers to liberty lurk in insidious encroachment by men of zeal, well-meaning but without understanding. -- Justice Louis D. Brandeis

Wim Godden

10 years ago
On 7/05/2016 1:34, Raja Kulasekaran wrote:
> I have encrypted php Application codebase which I may or may not have > access. > > So, I would like to know how the application behaving / profiling Database > queries through the .so or .dll level . > > Is there any php extension available which help me out to give the > statistics of > all the queries execution details ? >
Most DB servers will allow you to do this directly or indirectly. If you're using MySQL, there's a few options : - General query log (don't do this on a busy production server since it will produce massive log files and the I/O alone could bring down your server) : http://dev.mysql.com/doc/refman/5.7/en/query-log.html - MySQLProxy : http://philippeback.be/2013/02/logging-mysql-queries-with-mysqlproxy/ For Postgres : http://www.microhowto.info/howto/log_all_queries_to_a_postgresql_server.html Kind regards, Wim

Patrick ALLAERT

10 years ago
Le sam. 7 mai 2016 à 02:18, Wim Godden <wim.godden@cu.be> a écrit :
> On 7/05/2016 1:34, Raja Kulasekaran wrote: > > I have encrypted php Application codebase which I may or may not have > > access. > > > > So, I would like to know how the application behaving / profiling > Database > > queries through the .so or .dll level . > > > > Is there any php extension available which help me out to give the > > statistics of > > all the queries execution details ? > > > > Most DB servers will allow you to do this directly or indirectly. > > If you're using MySQL, there's a few options : > - General query log (don't do this on a busy production server since it > will produce massive log files and the I/O alone could bring down your > server) : http://dev.mysql.com/doc/refman/5.7/en/query-log.html > - MySQLProxy : > http://philippeback.be/2013/02/logging-mysql-queries-with-mysqlproxy/
MySQL Proxy is indeed what I mostly used, I've shared a few LUA scripts to help logging/debugging/profiling them: https://github.com/patrickallaert/MySQL-Proxy-scripts-for-devs

Johannes Schlueter

10 years ago
Hi, On Fri, 2016-05-06 at 19:34 -0400, Raja Kulasekaran wrote:
> Is there any php extension available which help me out to give the > statistics of > all the queries execution details ?
if you are on a development machine (thus no unrelated traffic) something like a query log (in MySQL general_log) might be the quickest and most simple way. However if you're using MySQL you might also look at pecl.php.ne/mysqlnd_uh which allows to overload low level calls in mysqlnd (thus below PDO or mysqli or so) from userland and adding your own logging logic. See http://php.net/manual/en/mysqlnd-uh.quickstart.query-monitoring.php Maybe you should also check the license agreement of the software you're using. Some people try to disallow that. (I can't tell whether such rules might be relevant and binding) johannes

Zeev Suraski

10 years ago
> On 7 במאי 2016, at 2:35, Raja Kulasekaran <cullsin@gmail.com> wrote: > > Hi, > > Sorry If I am asking this question in irrelevent forum. > Please suggest me the point of direction if not. > > I have encrypted php Application codebase which I may or may not have > access. > > So, I would like to know how the application behaving / profiling Database > queries through the .so or .dll level . > > Is there any php extension available which help me out to give the > statistics of > all the queries execution details ?
bit.ly/zraysa - you'd never want to look at database logs again! No PHP 7 version yet but we should have that sometime soon. (and everyone right, it's not the right list :) Zeev