0

If I have a PHP script that makes a MySQL call/query. Is there a way to log/audit the size of the response/data (in bytes) that is returned from that call?

I know I could use tcpdump, but that does not necessarily ensure the traffic stats I gather are for a certain transaction (IE: I may have 5 transactions at roughly the same time, making it impossible to determine one transaction from another).

WildBill
  • 9,143
  • 15
  • 63
  • 87
  • 1
    You may want to rephrase the ? to **Log the amount of data...** before the SO police nab you. :-) – yardpenalty.com Apr 02 '14 at 02:59
  • 1
    What sort of metrics are you looking for? An odometer on the connection itself? If so, you might want to create a MySQL proxy that can measure this for you. – tadman Apr 02 '14 at 03:05
  • I changed it from 'amount of data' to 'volume of data'. Is that ok? I'm unsure how else to ask for the size of the data in bytes that the call generates. :) – WildBill Apr 02 '14 at 13:33
  • I'm thinking I can do this by modifying the php source code. Though difficult, this should still be possible, correct? Or does anyone know why this would NOT work. – WildBill Apr 03 '14 at 09:46
  • show us your php script... – nl-x Apr 04 '14 at 15:00
  • @nl-x I don't have a particular script per say, I want to know if I can do it across all scripts hosted via a web server. – WildBill Apr 04 '14 at 16:15

1 Answers1

1

mysqli has a couple of functions that will give you some stats:

Some of the statistics available include:

  • bytes_sent - Number of bytes sent from PHP to the MySQL server
  • bytes_received - Number of bytes received from MySQL server

Take a look at this page to see the all the stats you can get if you're using the MySQL Native Driver: MySQL Native Driver statistics

kunal
  • 1,359
  • 10
  • 10
  • This is correct and works well, but is there a way that does not involve modifying an individual script? I'm guessing I could modify the php extensions and wrap around any calls, but is there anything else that does this across all php scripts that might already be on a server? – WildBill Apr 08 '14 at 07:03
  • It's difficult to know if it can be done without modifying the existing files without know how they are written. But, another way to approach the problem may be to use MySQL's [General Query Log](http://dev.mysql.com/doc/refman/5.6/en/query-log.html). It won't give you the amount of data, but it will you give you a complete log every query that is sent to the server and you won't have to modify any existing PHP code. – kunal Apr 09 '14 at 03:43