Custom CMS, HTTP content-length header value
Posted: Mon Aug 22, 2011 6:38 am
Hi everyone
I've built a custom CMS (content management system) on our intranet to make it easy to manage the content across several websites that we manage. However I realised that nowhere in my website code am I outputting the HTTP content-length header. I send last-modified using the modification date of the article from the database but not content-length.
On our website the HTML code is output to the browser using a single echo() statement at the end of the script, as opposed to being sent to the browser in different stages.
When looking at the HTTP headers of my output I notice "transfer-encoding: chunked" instead of a content-length.
Is that a problem?
I believe that header is HTTP 1.1, not 1.0 so could that cause problems with some proxies/firewalls that people may use?
How do I calculate the content-length?
Do I need to use PHP's output buffering functions... ob_get_length() etc?
Or is there a way of manually calculating it without too much of a performance hit?
I'm assuming it's a bit more complicated than just running strlen() on my output variable?
And even though we use UTF-8 throughout, I guess strlen() would be better than mb_strlen() as the former gives me the value of bytes, the latter giving the number of characters in the string.
Cheers, B
I've built a custom CMS (content management system) on our intranet to make it easy to manage the content across several websites that we manage. However I realised that nowhere in my website code am I outputting the HTTP content-length header. I send last-modified using the modification date of the article from the database but not content-length.
On our website the HTML code is output to the browser using a single echo() statement at the end of the script, as opposed to being sent to the browser in different stages.
When looking at the HTTP headers of my output I notice "transfer-encoding: chunked" instead of a content-length.
Is that a problem?
I believe that header is HTTP 1.1, not 1.0 so could that cause problems with some proxies/firewalls that people may use?
How do I calculate the content-length?
Do I need to use PHP's output buffering functions... ob_get_length() etc?
Or is there a way of manually calculating it without too much of a performance hit?
I'm assuming it's a bit more complicated than just running strlen() on my output variable?
And even though we use UTF-8 throughout, I guess strlen() would be better than mb_strlen() as the former gives me the value of bytes, the latter giving the number of characters in the string.
Cheers, B