<?php
// Connect to mysql server
$link = mysql_connect(HOST, USER, PASSWORD);
if(!$link) {
die('Could not connect to server: ' . mysql_error());
}
// Select database
$db = mysql_select_db(DATABASE);
if(!$db) {
die('Cannot use the database');
}
mysql_set_charset('charset=utf8', $link);
//code
?>
I am php beginer.I have written a simple php HTTP API which read some data from database and return in body. This API is accessed by many uses application asynchronously. When we increase the number of user more than 200 each second, i nam getting following warning
PHP Warning: mysql_connect() [<a href='function.mysql-connect'>function.mysql-connect</a>]: Too many connections in /home/ws/public_html/include/get_details.php on line 3
I want to know best solution for it.
Thanks
first you can use mysqltuner to check your db status. Other solution, use redis or memcache to reduce the connections. If you have your sessions stored in DB, try to change and use redis.phpredis
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With