On a LAMP stack, how to limit the number of concurrent connections and serve a static page for those who are beyond that limit?

0

Issue

I’m aware of the Apache directives MaxClients and ListenBacklog. I’m trying to set a limit of, let’s say 100 concurrent connections after which the new connections will be served a static page.
Can this be done? Should MaxClients and ListenBacklog be higher or lower than that limit? How can I test it?

Solution

Here’s how I did it:
Let’s say that I want to allow X concurrent requests, after which the following Y concurrent requests will stay in a queue, waiting for the first X to finish, and everything exceeding X+Y will be served a static page:

  1. In httpd.conf the following directives must be set:

    MaxClients X
    ServerLimit X
    ListenBacklog Y
    
  2. Logged as root in MySQL, set max_connections:

    set global max_connections = X
    
  3. Edit the .htaccess file from your server’s public root folder:

    ErrorDocument 503 error_503.html
    
  4. Make sure that your error_503.html is served in one request. All stylesheets and scripts must be in this file. If you want to include images, you’ll have to use the data uri scheme. Also, you’ll have to slice your images up because in IE data URIs have to be smaller than 32KiB.

Answered By – Valentin Brasso

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave A Reply

Your email address will not be published.

This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish. Accept Read More