2

I have a PHP-based that uses MySQLi's connection persistence feature, but I'd like to fully confirm that it's working.

I expect that the information I need is somewhere in the results of the mysqli_get_connection_stats($link) function, or the corresponding MySQLND Statistics section available from php_info(), but I'm not really sure which values give me the information I need.

For example, I'm seeing values for connection_reused, does this indicate a persistent connection re-used, or a regular connection that hasn't timed out yet? pconnect_success is at 1, but I'm uncertain as connect_success is at 40, suggesting that there have been 39 non-persistent connections according to the PHP manual, but I'm unclear on why these may occur (as all scripts on the same host are using persistent connection methods).

One particular point of confusion is the active_connections stat which currently returns 18446744073709551578, I'm assuming it's overflowing somehow as that's close to the limit of a 64-bit integer, and I'm fairly certain I'm not maintaining quite so many connections!

I guess I'd just like to know how exactly I should read these stats in order to determine whether MySQLi is correctly using persistent connections or not.

Haravikk
  • 3,109
  • 1
  • 33
  • 46
  • 2
    persistent connections are almost always a bad idea –  Aug 13 '14 at 21:12
  • Care to elaborate? MySQLi's connection persistence performs automatic rollbacks, table unlocking etc., and the benefit in performance was noticeable on a previous host, I'm just not sure if they're still working as expected on my new one. – Haravikk Aug 14 '14 at 07:55
  • @Haravikk, Could you please add some more information about your new host's configuration: WEB-server, PHP version? Also, are you certain, that you did not observe such behavior on old host? – TooroSan Aug 17 '14 at 23:05
  • It looks like you are having 40 child PHP processes on new host, so each of them have its own persistent connection. But I can't say more certain without info about your host configuration. :( Take a look at a number of PHP processes run on your new host, - if it is equal 40 - thats' the reason of such a number of connections. ;) – TooroSan Aug 17 '14 at 23:13
  • Also, to get a number of connections to the DB, I would recomend you to run `show processlist;` on your MySQL server. Here are related quesitons with a little bit more info abobut this: http://stackoverflow.com/questions/7432241/mysql-show-status-active-or-total-connections http://stackoverflow.com/questions/824428/number-of-db-connections-opened – TooroSan Aug 17 '14 at 23:24

1 Answers1

0

Use mysqli_ping() or mysqli::ping() function to be sure the connection is alive. See http://php.net//manual/en/mysqli.ping.php

clover
  • 4,910
  • 1
  • 18
  • 26