Reputation: 354
The error message occur when I have multiple request in the server. and my server hosting told me that my max user connection is only 15. how can i manage this request and avoid this error.?
Upvotes: 2
Views: 3188
Reputation: 75
For those still looking for the latest information on this topic mysql_pconnect: This extension was deprecated in PHP 5.5. 0, and it was removed in PHP 7.0. Instead, the MySQLi or PDO_MySQL extension should be used. One can try prepending "p:" to the host name in connecting to mysqli in order make use of persistent behavior.
Alternatives to mysql_pconnect include:
1) mysqli_connect() with p: host prefix Example:
mysqli_connect('p:192.168.x.y', 'USER', 'PWD', 'DB', 3306);
2) PDO::__construct() with PDO::ATTR_PERSISTENT as a driver option**
Example:
try {
$conn = new PDO("mysql:host=$mysql_host;dbname=$database", $mysql_user, $mysql_password, array(PDO::ATTR_PERSISTENT=>true));
} catch (PDOException $e) {
die ("<b>Cannot connect to database, check user credentials.</b>");
}
Upvotes: 0
Reputation: 48357
Switch to a different hosting provider/package
Improve the performance of your queries by refactoring the queries and changing indexing
Don't open db connections in your code until you need to run a query
explicitly close db connections immediately after they are no longer required
If you are running the same queries repeatedly, cache the data outside the DBMS (much less efficient / requires much more code than using DB caching)
Upvotes: 1
Reputation: 351
Depending upon your environment the answer can vary greatly. The main point point is you need to better manage your connections; remember to close them when you are done, re-use them when you can. Without knowing your stack I can't give you better advice. You may wish to check if you are opening up a persistent connection and not closing it.
Upvotes: 1
Reputation: 1306
In my.cnf put:
max_connections=100
or if you can't change this file, you'll have to limit the number of connections in your php software (if you are using a pool or similar) to avoid reach this limit.
Upvotes: 3