HTTP/1.0 Connection: keep-alive, but Apache replies with HTTP/1.1 Connection: close?

Operating System & Version
CentOS 7.9
cPanel & WHM Version
WHM v104.0

Benjamin D.

Well-Known Member
Jan 28, 2016
218
34
78
Canada
cPanel Access Level
Root Administrator
Hi, Apache config question here. I'm dealing with an unusual project where I need to interface a WHM v104.0 w/ Apache 2.4 server with an old piece of technology from the early 90's with the simplest HTTP requests possible, so I have a socket on the old computer connected to the WHM server and I send a header like this:
HOST: somehost.com
GET /myscript.php HTTP/1.0
Connection: keep-alive

...but I'm getting back this response from Apache: (simplified here for readability)
HTTP/1.1 200 OK
Connection: close

It's halfway decent as it's not chunked (even though it's HTTP/1.1?!) and the content comes in clean so this is very good, but the issue is that it closes the connection IMMEDIATELY after the SERVER sent its last page bytes. The client is so old and slow that it randomly cannot grab the last few kilobytes before the connection is closed.

I went in WHM > Apache Configuration > Global Configuration and I see everything that's needed for a keep alive connection enabled, yet Apache seems to revert to "Connection: close" by itself.

Keep-Alive -> On
Keep-Alive Timeout -> 10
Max Keep-Alive Requests -> 200
Timeout -> 120

I have also tried adding this to a .htaccess file in the directory where the requested script is:
<ifModule mod_headers.c>
Header set Connection keep-alive
</ifModule>

...but I'm getting back this response from Apache: (simplified here for readability)
HTTP/1.1 200 OK
Connection: keep-alive, close
... and it still closes the connection before the last few kilobytes are saved in the old computer (exactly the same).

Is WHM ignoring its own Global Configuration settings? I understand non-SSL HTTP/1.x requests are extremely old and not secure and should not be used in 2022 etc, but I'd like to know how to make it work in a way that old/slow technology can have at least a couple seconds to register the last few kilobytes of DATA sent by Apache before the door is slammed in its face and the connection is closed :mad:
 
Last edited:

cPRex

Jurassic Moderator
Staff member
Oct 19, 2014
15,275
2,432
363
cPanel Access Level
Root Administrator
Hey there! Is your server busy at all? I'm wondering if it needs those resources as outlined here, as this is a good explanation of that value on a busy system:


Alternatively, as a test, what happens if you disable keep-alive completely? Is the client able to send multiple requests to get the data it needs or does it just fail?

I haven't heard of cPanel ignoring these options before as that would be a pretty serious issue with the Apache configuration, but if you can reliably reproduce this it may be best to submit a ticket to our team so we can see it in action.
 

Benjamin D.

Well-Known Member
Jan 28, 2016
218
34
78
Canada
cPanel Access Level
Root Administrator
Hi, answers to your questions:

It's a busy server, but not to the point of being slow. The response header and the first few kilobytes from this WHM server are pretty much instantaneous. The server is not overloaded at all.

If I disable Keep-Alive under WHM > Apache Configuration > Global Configuration, I'll have to rebuild Apache, on a production server. Are you sure DISABLING Keep-Alive would make it work?

I forgot to tell, but this WHM server also runs CSF Firewall, but I've tried to disable it for a minute and run tests and the outcome is exactly the same. Though, I have tried getting a static file instead of a PHP script (e.g. a .PDF file) and Apache correctly issues a "Connection: keep-alive" style of response header and this reliably downloads in full before the connection is closed. So it seems to only issue a "Connection: close" response header and abruptly shut down the connection near the end, before the last few KB, when it's a PHP script. For static files it works fine. Weird?
 
Last edited:

Benjamin D.

Well-Known Member
Jan 28, 2016
218
34
78
Canada
cPanel Access Level
Root Administrator
Sorry, I misread earlier, it says "Apache configuration must be rebuilt and Apache restarted." but given that having it ON works for static files, I don't think turning it OFF would fix the issue that PHP scripts are not served on a Keep-Alive connection, at least I don't see the logic in this change. I wonder if it could have anything to do with a setting in suphp? The server is on suphp 7.4 at the moment, built of course with WHM's EasyApache 4.