GoAdmio

maxkeepaliverequests

Read or set Apache's MaxKeepAliveRequests (the most requests one keep-alive connection may serve; default 100), then reload the web server

On this page: Overview · Quick start · Syntax · Options · Output · Examples · Troubleshooting · Details · See also


Overview

/go/maxkeepaliverequests sets Apache's MaxKeepAliveRequests directive in the main Apache configuration file. This is the number of requests Apache serves on one persistent (keep-alive) connection before it closes the connection. The command:

Higher values let browsers reuse a connection for more files, which speeds up page loads but keeps worker processes busy longer. 0 means unlimited. The setting only matters when KeepAlive is on (see keepalive).

It changes Apache only. If the server runs Nginx, the edit has no effect.


Quick start

# Set the default (100 requests per connection)
/go/maxkeepaliverequests

The web server is reloaded automatically.


Syntax

/go/maxkeepaliverequests [number]
/go/maxkeepaliverequests return
Form Behavior
/go/maxkeepaliverequests Sets MaxKeepAliveRequests 100, then reloads.
/go/maxkeepaliverequests <number> Sets that value, then reloads.
/go/maxkeepaliverequests return Prints the current value and changes nothing. The word is not case-sensitive.

If the first argument starts with -- (for example --force), it is ignored and 100 is set.

[!WARNING] Pass only the number. Everything after the command name is written into the Apache configuration as typed. For example, /go/maxkeepaliverequests 200 --noreload writes the line MaxKeepAliveRequests 200 --noreload, which is invalid and makes Apache refuse to reload or restart. See Troubleshooting.


Options

This command has no working options. It takes one optional argument.

Argument Required Default Notes
<number> No 100 A whole number of requests. 0 means unlimited. Nothing checks the value (see Validation).
return No — Prints the current value instead of setting one.
--noreload No — Does not work. The reload always runs. See The reload.

Output

Outcome What you get
Value set MaxKeepAliveRequests updated successfully., followed by whatever reload prints.
return The value from the first matching line. Blank if there is none.
Unsupported operating system Unknown operating system. Nothing is changed.

The success message is printed even if the file could not be changed, so it does not prove the change was made. Check with return.

Every run is also recorded in /var/log/go/maxkeepaliverequests.log.

[!NOTE] return ends with exit status 1, and return does not reload the web server. In scripts, read the output instead of relying on the exit status.


Examples

# Use the default of 100
/go/maxkeepaliverequests
# Allow 500 requests per connection
/go/maxkeepaliverequests 500
# No limit
/go/maxkeepaliverequests 0
# Show the current value
/go/maxkeepaliverequests return

Troubleshooting

Symptom Likely cause Fix
Apache refuses to reload or restart after the command Extra text was written after the number, such as --noreload. Open the configuration file (see Files it changes), correct the MaxKeepAliveRequests line, check it with apachectl configtest, and reload.
--noreload did not stop the reload The option does not work. None. Plan for the web server to reload every time.
The new value has no effect The server runs Nginx, or KeepAlive is off, or another file sets the directive later. Check keepalive, and see Files it changes.
return prints a word instead of a number The first line containing the name is a comment, or it is indented or separated by a tab. Open the file and read the real line, or set a value to add a clean one.
Unknown operating system. The operating system name in /usr/local/goadmio/linux/os.db isn't one the script knows. The script supports AlmaLinux, Rocky, CentOS, Red Hat, Fedora, Debian, and Ubuntu.
The Apache file did not exist and a stray file or an error appeared Apache isn't installed, so the line is written into a new file, or fails. Install Apache, or remove the stray file.
/etc/apache2/vhost/port.conf is missing on Debian The command deletes it every time it runs on Debian. See Debian side effect.
Permission denied The command was not run as root. Adding a missing line writes to the file without sudo. Run it as root.

Details

Files it changes

The script reads the operating system from /usr/local/goadmio/linux/os.db.

Operating system File
AlmaLinux, Rocky, CentOS, Red Hat, Fedora /etc/httpd/conf/httpd.conf
Debian, Ubuntu /etc/apache2/apache2.conf

Only this one file is edited. A MaxKeepAliveRequests line in a file it includes, or inside a virtual host, is not changed and may override the new value.

How a value is written

Situation Result
An uncommented MaxKeepAliveRequests line exists Every such line is replaced with MaxKeepAliveRequests <value>, keeping its indentation.
The directive is missing, or only exists as a comment A new MaxKeepAliveRequests <value> line is added at the end of the file.

Validation

The command does not check the value. Pass a single whole number.

The reload

After the change, the command always runs reload, which reloads PHP-FPM and the active web server. The script tries to skip this when --noreload is passed, but the test is written incorrectly, so the reload is never skipped. A reload is graceful, but it fails if the configuration is invalid.

Debian side effect

On Debian only, the command deletes /etc/apache2/vhost/port.conf every time it runs, before it does anything else. This also happens with return. Ubuntu and the RHEL family are not affected.


See also

Command Description
keepalive Read or set Apache's KeepAlive directive
keepalivetimeout Read or set Apache's KeepAliveTimeout directive
reload Reload PHP-FPM and the active web server
web Restart or reload the active web server
apache Switch the server from Nginx to Apache, or rebuild a domain's Apache virtual host
nginx Convert a GoAdmio server from Apache to Nginx