-1

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);
Dharman
  • 30,962
  • 25
  • 85
  • 135
  • You could try it but a decent host and your own VPS at least would probably help the situation and offer a longer term solution. – Dave Jan 04 '21 at 15:31

1 Answers1

0

I don't think that persistent connections will help you, basically your issue of max_connection_error will remain the same or even worst.

So I will suggest take @dave advice and to deploy your website to another host that you can change this configuration or to your own VPS server that ypu can control it and change what ever you want.

This is to docs from PHP website where you can fond more info about persistent connections, advantages and disadvantages

https://www.php.net/manual/en/features.persistent-connections.php

More info and tests results you can find in this website:

https://meta.wikimedia.org/wiki/Why_persistent_connections_are_bad

shushu304
  • 1,506
  • 1
  • 7
  • 15