Why does phpinfo() display "Active Persistent Links" of 0/1 when I know there are more open connections to my database?

Article:
00129
Last Reviewed:
10th January 2024
Revision:
1

Please read www.php.net/manual/features.persistent-connections.php.

Currently on UNIX, Apache and PHP is a single-threaded process where 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 which has never connected to the database (Active Persistent Links = 0) or one which has connected to the database (Active Persistent Links = 1). This is easy to confirm for yourself:

  1. Stop the HTTP server and configure it so only you can connect (or arrange that no-one else connects to it whilst you are testing). Make sure allow_persistent = On is in your php.ini file.
  2. Start the HTTP server.
  3. Browse to a PHP page that calls phpinfo() — it will display "Active persistent Links = 0". No matter how many times you refresh this page, it will show 0.
  4. Browse to a PHP page which connects to your database with odbc_pconnect().

  5. Browse the page in step 3 again and hit refresh a number of times. You will see "Active persistent Links" change between 0 and 1 even though there is no activity on your web server other than yourself. This is the main HTTP server farming out your HTTP request to different children, one of which made the connection in step 4 and all the others which have never made a database connection.

The only way to get Active Persistent Links greater than 1 is to open more than one persistent connection in a single PHP script.

Applies To

Knowledge Base Feedback

* Did this content help you?
* Please select one option based on your first choice:

(* Required Fields)