# How to get trace of all database queries executed by php

- Thread: https://externals.io/message/93101
- Original archive: https://news-web.php.net/php.internals/93101
- Started by Raja Kulasekaran on 2016-05-06T23:34:29+00:00
- Messages: 8
- Reply by email to internals@lists.php.net
- More for agents: search with https://externals.io/search.md?q={query} · JSON API at https://externals.io/api · documentation at https://externals.io/llms.txt

---

## #93101 — Raja Kulasekaran — 2016-05-06T23:34:29+00:00

URL: https://externals.io/message/93101#93101

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

---

## #93102 — Stanislav Malyshev — 2016-05-07T00:06:17+00:00

URL: https://externals.io/message/93101#93102 · In reply to: #93101

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

---

## #93103 — Walter Parker — 2016-05-07T00:07:20+00:00

URL: https://externals.io/message/93101#93103 · In reply to: #93101

> 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

---

## #93104 — Yasuo Ohgaki — 2016-05-07T00:15:36+00:00

URL: https://externals.io/message/93101#93104 · In reply to: #93102

Hi,


>
> > […]
>
> 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

---

## #93105 — Wim Godden — 2016-05-07T00:18:04+00:00

URL: https://externals.io/message/93101#93105 · In reply to: #93101

> 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

---

## #93116 — johannes@schlueters.de — 2016-05-08T17:51:33+00:00

URL: https://externals.io/message/93101#93116 · In reply to: #93101

Hi,


> 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

---

## #93118 — Zeev Suraski — 2016-05-08T19:28:41+00:00

URL: https://externals.io/message/93101#93118 · In reply to: #93101

> 
> 
> 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

---

## #93132 — Patrick ALLAERT — 2016-05-09T21:19:07+00:00

URL: https://externals.io/message/93101#93132 · In reply to: #93105

Le sam. 7 mai 2016 à 02:18, Wim Godden <wim.godden@cu.be> a écrit :

> 
> > […]
> Database
> > […]
>
> 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


>
> For Postgres :
>
> http://www.microhowto.info/howto/log_all_queries_to_a_postgresql_server.html
>
> Kind regards,
>
> Wim
