When a user logs in the site, an AJAX call is made every 10 seconds, to update data from a delivery service.
It works OK, but at night when the demand for deliveries increases a lot, there begin to be these connection errors. I'm on a GoDaddy server, so I can't change the 'max_user_connections' to a higher value.
I was reading about persistent connections, but I don't know if it will work.
By adding a "p:" to the connection before the host like this:
$link = mysqli_connect("p:" . DB_HOST, DB_USER, DB_PASS);
I think that when an AJAX call runs a new connection to the DB is made in the PHP file. Will the persistent connection avoid this and reuses a connection that each users already has?
If a persistent connection is not the right path for this, what could it be?
Errors in PHP Log:
[06-Dec-2020 00:13:22 UTC] PHP Warning: mysqli_connect(): (42000/1226): User 'delivery' has exceeded
the 'max_user_connections' resource (current value: 30) in
/home/ofc1m1i4xaac/public_html/xdelb.com/classes/get_delivering.php on line 15
PHP file get_delivering.php:
<?php
session_start();
session_write_close();
if (!isset($_SESSION['user_id']) ) {
// header("Location: ../index.php");
exit();
}
require_once("../includes/psl-config.php");
$link = mysqli_connect(DB_HOST, DB_USER, DB_PASS);
mysqli_select_db($link, DB_NAME);
mysqli_set_charset($link, "utf8");
$append="";
$number=1;
$result = mysqli_query($link, "SELECT orders_header.`id`, `picking_time`, `delivery_address`, orders_header.`created_at` FROM `orders_header` inner join delivery_guys on delivery_guys.id=dv_guy_id `store_id`=".$_SESSION['user_id'] );
if ( mysqli_num_rows($result) > 0) {
while($row = mysqli_fetch_array($result)){
// do stuffs
}
}
mysqli_close($link);