Why does phpinfo()
display "Active Persistent Links of 0/1" when I know there are more open connections to my database?
On UNIX, Apache and PHP is a single-threaded process. The main web server creates children to deal with HTTP requests. When you set allow_persistent
to On
in your php.ini
file and use odbc_pconnect
, a persistent connection will be created in one of the HTTP child processes. However, it is up to the main HTTP daemon which child will handle the request, and the persistent connection only exists in that HTTP child. You cannot control which HTTP child process will answer the request, so it may be one that has never connected to the database (Active Persistent Links = 0
) or one that has connected to the database (Active Persistent Links = 1
). To confirm this:
- Stop the HTTP server and configure it so that only you can connect (or arrange that no one else connects to it during this test). Make sure
allow_persistent = On
is present in yourphp.ini
file. - Start the HTTP server.
- Go to a PHP page that calls
phpinfo()
. The function output should containActive persistent Links = 0
. No matter how many times you refresh this page, theActive persistent Links
value should be0
. - Go to a PHP page that connects to your database with
odbc_pconnect()
. - Go to the page in step 3 again and choose Refresh a number of times. "Active persistent Links" should fluctuate between 0 and 1 even though there is no activity on your web server other than yours. This is the main HTTP server assigning your HTTP requests to different children, one of which made the connection in step 4.
The only way to get the Active Persistent Links
total to be greater than 1 is to open more than one persistent connection in a single PHP script.