My colleague asked me to help explain a problem: a PHP-generated redirect request generates two completely different records in the Nginx log. the response body size is zero bytes, the other response body size is five bytes. when I am older, my sense of smell is no longer sensitive to problems. first... my colleague asked me to help explain a problem: a PHP-generated redirect request generates two completely different records in the Nginx log. the response body size is zero bytes, the other response body size is five bytes.
Now that I am older, my sense of smell in the face of problems is no longer sensitive. I feel that nothing is correct. I wonder if I forget to quit after redirection, and there is content output later, however, I checked the code and found that there was no problem. The code is as follows:
After a large circle, I suddenly realized that the environment was Nginx + PHP and the response was not "Content-Length". The data was sent through "Transfer-Encoding, therefore, the empty response body for redirection is actually similar:
0 \ r \ n
Not many, exactly five bytes. for details, refer to Chunked transfer encoding. in this case, PHP actively outputs a "Content-Length: 0 "may be better.
How can we explain the zero-byte response? Query logs can be found in the following two situations:
HEAD "/path HTTP/1.1" 302 0
GET "/path HTTP/1.0" 302 0
The former is a HEAD request and does not need a response body. The latter is HTTP/1.0 and does not support "Transfer-Encoding 」.