Apache/PHP/MySQL persistent connections have this type of bad status because Apache handles each request growing up php process, each getting 1 persistent connection. When site visitors scale, MySQL reachs max connections limit all the apache/php child processes, each with 1 persistent connection. Additionally, there are the problems of temporary tables, user variables, charsets, transactions and last-place-id.

During my situation, we do not suffer from the second issues, because we're only Reading through from MySQL. You will find no updates towards the db: these are addressed by another group of scripts on the different machine. The scripts you want to have persistent connections would be the server-finish of AJAX connections, coming back JSON data.

Each pageview has 5 AJAX demands, so 6 different php child processes are began around the server for every page asked for (5 ajax, 1 html). Ideally, I possibly could only have 1 connection in the php/ajax server to MySQL. This connection could be shared by all php child processes.

So, how do i do that? Must I use another webserver software apart from apache? ngynx?


UPDATE: In cases like this, the proper way to connect with the MySQL server (http://bit.ly/15rBDP):

  • using mysql native driver (mysqlnd) and mysqli
  • each client reconnecting while using mysql-change-user function
  • using MYSQLI-NO-CHANGE-USER-ON-PCONNECT in php config ('coz we don't have to cleanup).


To explain my question, what i wish to have is: ALL php client processes, hooking up through just one persistent connection. This connection is determined, went and saved some how (my question), but brand new php client processes realize it and may utilize it. The issue with apache/php is the fact that each php client process has 1 connection. Basically serve 20,000 pages each minute, you will see 20,000 persistent connections. I would like the 20,000 php child processes hooking up to at least one unique, central, persistent link with mysql.

Browse the recognized answer about this publish : http://stackoverflow.com/questions/1340859/which-is-better-mysqlconnect-or-mysqlpconnect

Simply, using mysql persistent connections might be bad or good, with respect to the hardware assets you have along with the way you code your programs.

A php native mysql connector is incorporated in php 5.3 that has enhanced support for persistent connections.



You need to do understand that getting just one (persistent) connection for your demands, effectively serializes all demands for your server. So request C needs to watch for request B to complete, which needs to watch for request A to complete etc.

So getting one connection turns your multi-threaded/multi-process webserver right into a single-threaded application.