How can I see how many connections have been opened during the current request via mysql_connect
in PHP running on Apache?
I know that if I call mysql_connect
function 100 times with the same parameters, it will always return the same connection link. It will not start new connection once the connection already exists.
But I just want to make sure mysql_connect
is not starting a new one.
I am working with a legacy system which contains many mysql_connect
function calls.
Is there any setting in Apache or is there any way I can log this number of connections in Apache or MySQL log file?
Current connections status:
Look at
Threads:
count. More detailed information about current connections can be obtained with the commands:FYI
mysqladmin -v -uroot -ppass processlist
is analog ofshow full processlist
.Commands can be shortened to any unique prefix, and called simultaneously:
I dont think you can see the number of connection, but can limit the connections to the mysql server.
There are other useful variables regarding connections and in your particular case variable
Connections
might help find out if your code is making too many connections. Just check it value before and after running code.Connections
The number of connection attempts (successful or not) to the MySQL server.
Threads_cached
The number of threads in the thread cache.
Threads_connected
The number of currently open connections.
Threads_created
The number of threads created to handle connections. If Threads_created is big, you may want to increase the thread_cache_size value. The cache miss rate can be calculated as Threads_created/Connections.
Threads_running
The number of threads that are not sleeping.
I think there are a couple of ways:
or you can do a
SHOW PROCESSLIST
and find out unique values in theId
column. In old PHP APImysql
, there ismysql_list_processes
function that does the same asSHOW PROCESSLIST
, too.But first one should work for you. And perhaps you might like to check on other STATUS variables
You could use the MySQL command show processlist to get the number of connections.