Search code examples
phpmysqlangularionic-frameworkgodaddy-api

GoDaddy server closing connection when client sends multiple POST requests in a short interval of time


I’m using Ionic Framework (Angular v9) to send POST requests to the PHP files hosted on the GoDaddy server. POST requests work fine until the client sends them intermittently. However, when the client starts to send multiple POST requests to the server the requests are being rejected. The server responds with one of the following errors:

  1. err connection closed
  2. err connection timed out
  3. err_connection_reset

Scenario where such errors are spotted - Autocomplete implementation. I’ve a product Table (phpmyadmin - MySQL DB) and a PHP file to retrieve data from that table. There is a textbox on the client side app. The user begins entering the name of the product. The app fetches the values from the textbox and sends a POST request to the server. The server extracts the value from POST request and queries the table for values that match the input string. Top 5 such results are sent back to the client.

This flow works as long as the client fires the POST requests slowly, i.e. enough time interval (a few seconds) elapses between 2 requests. However, this ideal scenario is impractical. User’s typing speed wouldn’t allow the passage of such interval. I want to query the DB and have the server return results on each keydown event.

But the problem is that the server is closing the connection / resetting the connection when the same client sends too many POST requests to the server without leaving enough time interval between any 2 requests.

Thank you in advance for help.


Solution

  • If you can you need to learn actual limitation (allowed POST request rate from your client to the server), then work off that.

    But generally speaking you need to employ a debounce technique. Even if your host provider would allow that many requests it is not a great idea to have that volume coming out of a single client.

    1. You can use in-built debounce for components such a ion-searchbar
    2. You can use debounceTime RXJS operator to pipe your POST requests (so that it won't fire more often than it should)
    3. You can assess caching of such auto-complete details on client to prevent frequent requests

    Example with ion-search:

    <ion-searchbar debounce="500"></ion-searchbar>
    

    Example with debounceTime and formControl:

      constructor() {
        this.searchControl = new FormControl();
      }
    
      ngOnInit() {
    
        this.searchControl.valueChanges
          .pipe(debounceTime(700))
          .subscribe(search => {
            
          });
      }