clarkk clarkk - 5 months ago 8
PHP Question

Tell if HTTP request is Keep-Alive

How to tell if a HTTP request is a Keep-Alive connection?

Is it possible to detect via PHP if a HTTP request is Keep-Alive?

If a connection is not Keep-Alive I want to return an error as a part of the API protocol to reduce the use of resources at each SSL handshake and to speed up the communication between server and client

Answer

You can check it with:

function isConnectionKeepAlive() {
    if(getallheaders()["Connection"] == "Keep-Alive") {
          return true;
    } else {
          return false;
    }
}