Search code examples
phpapachehttphttp-headerscontent-length

HTTP Content-Length header has 1 byte too many


I'm writing a (PHP) script that serves files to the client. Among others, the Content-Length header is sent, only it has one byte too many. I discovered this when I put the content length in a different header, and compared the two:

$filesize = filesize($file);
header('Content-Length: ' . $filesize);
header('X-Content-Length: ' . $filesize);

Result:

Content-Length: 3481
X-Content-Length: 3480

Even when hard-coding 3480 into the header() function, this is the outcome. I suspect Apache doing this to my headers.

What might be causing this?

Edit: To give some context: I think Zend Framework is causing this: I'm refactoring code that is currently in production (and working) to ZF, where the problem occurs. When I try this code outside of ZF, all is well. Maybe ZF is doing output buffering, and re-sending the headers itself or something, but I don't really know ZF that well.


Solution

  • This was not Apache's doing, but a space before a PHP open tag in combination with output buffering.