25
When I check the headers I’m sending on a php page, which is installed locally, I always see this Connection: Keep-Alive
.
Example:
var_dump(getallheaders());
Exit:
array (size=7)
'Host' => string '127.0.0.1' (length=9)
'User-Agent' => string 'Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:39.0) Gecko/20100101 Firefox/39.0' (length=76)
'Accept' => string 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8' (length=63)
'Accept-Language' => string 'pt-BR,pt;q=0.8,en-US;q=0.5,en;q=0.3' (length=35)
'Accept-Encoding' => string 'gzip, deflate' (length=13)
'Cookie' => string '_ga=GA1.1.1775431020.1436189521' (length=31)
'Connection' => string 'keep-alive' (length=10)
- What does it mean
Keep-alive
? - What’s he good for?
From the explanatory text of W3 (https://www.w3.org/Protocols/HTTP/1.1/draft-ietf-http-v11-spec-01#Connection) the image (not the text) seems to describe the behavior incorrectly. She gives the idea that the form of packet traffic is different on the way when in fact there is only a reduction of time on the server because it does not close the connection. Another misconception in the image is that we understand that Keepalive is a protocol other than HTTP. The right one would be "With Keepalive" and "No Keepalive".
– Pagotti
Take the liberty of editing the answer by changing the image caption. It really gets the impression that HTML and Keep Alive are separate protocols.
– lazyFox
Seeing the example image is much easier to understand. + 1 For it.
– Florida
A small addendum, since HTTP/1.1 connections are persistent by default, that is, unless the client is HTTP/1.0 there is no big reason to send the header
Connection: keep-alive
to the server.– Anthony Accioly