My shared server limits the number of concurrent connections to MySQL from PHP. Sometimes when I receive more traffic and each person needs to access the DB, they get rejected due to this max connection limitation. I was hoping that mysqlp_connect would solve the problem, but apparently a persistent connection does not keep one connection open for all users but for each user.
Is there anyway to have just ONE MySQL link always open on the server and have every user use only that link instead of creating a new link for each user?
I am only pulling a quote from this text, but I suggest you read this.
In my case, I would create a connection and discard it when finished for each operation, because the overhead was so small that it didnt affect any of my systems.
In your case you would have to look over your code and judge just how much overhead this would take; typically you would benchmark this.
” The answer here is extremely simple — efficiency. Persistent connections are good if the overhead to create a link to your SQL server is high. Whether or not this overhead is really high depends on many factors. Like, what kind of database it is, whether or not it sits on the same computer on which your web server sits, how loaded the machine the SQL server sits on is and so forth.
The bottom line is that if that connection overhead is high, persistent connections help you considerably. They cause the child process to simply connect only once for its entire lifespan, instead of every time it processes a page that requires connecting to the SQL server. This means that for every child that opened a persistent connection will have its own open persistent connection to the server.
For example, if you had 20 different child processes that ran a script that made a persistent connection to your SQL server, you’d have 20 different connections to the SQL server, one from each child. “
Source: http://php.net/manual/en/features.persistent-connections.php
I hope this help you!