Forum Moderators: coopster
Here are the headlines:
* Conteg.include
*
* Content-Negotiation + Cache-Control for PHP produced web-output
* - Request/Response Headers attempt to be RFC-compliant
* - Compression is load-balanced by default
* - Document-wide multi search/replace available
* - Single array-parameter switches negotiation on/off:
*
* No switches: auto-negotiates Accept-Encoding (compression), User-Agent
* Add:
* +Modified-date: auto-negotiates If-Modified-Since, If-Unmodified-Since
* +Expiry time: auto-sends Expires
* +Etag: auto-negotiates If-None-Match, If-Match, If-Range
* +Ranges: auto-negotiates Range, If-Range
* +Charset: auto-negotiates Accept-Charset
* +Language: auto-negotiates Accept-Language
* +Media-Type auto-negotiates Accept
*
* With the appropriate switches, the routine will auto-send the correct
* +304 Not Modified, 406 Not Acceptable, 412 Precondition Failed, 416 Requested
* +Range Not Satisfiable, 206 Partial content or 200 OK page + full headers.
* Change Log:
* 0.12.2: Added $_num_cpu for SMP boxes (like mine!) 18 Aug 06
* 0.12.1: Added sendStatusHeader() + 404 responses (used to create 02 Ju1 06
* +custom Error-pages).
* 0.12: Added requestNoCache(), requestNoStore(), 04 Jun 06
* +$_cache_control_response + $_cache_control_request arrays.
[edited by: coopster at 3:01 am (utc) on Aug. 6, 2008]
Do you have any step by step install instructions for a newbie?
The following comes from "Help, Advice + Other Stuff" (begins line #1937).
* How to use:
*
* Before use: change $_num_cpu to the number on *your* machine (default 1)
*
* Simplest possible usage requires 3 lines:
* 1 Turn Output Buffering on.
* 2 Include the Class file.
* 3 On the *very* last line create an instance of the Class.
*
* ------------Start of file---------------
* ¦<?php
* ¦ ob_start(); // <==== line 1
* ¦ include('Conteg.inc'); // <==== line 2
* ¦
* ¦... the page ...
* ¦
* ¦ new Conteg(); // <==== line 3
* ¦?>
* -------------End of file---------------- The above will auto-negotiate
Accept-Encoding(load-balanced compression) &
User-Agent.
Please note that the default for the program is to print (output ob-contents) immediately on declaration, which is why--in the example above--it needs to be declared upon the absolute final line. If you are to conduct any content-negotiation that requires programmatic-mediation (
Accept-Languagewould be a good example) then the Class would need creating with a
'noprint' => TRUEparameter at the beginning, and
$Encode->show()declaration at the end. That does NOT necessarily apply to the following discussion.
In order to add the Modified-date (
If-Modified-Since,
If-Unmodified-Since) & ETag (
If-None-Match,
If-Match,
If-Range):
This is the replacement for 'line 3' above (copied from lines #2000-2008 within Class):
* Here is the simplest HTTP/1.1 usage:
*
$param= array(
'use_etag'=> TRUE,// default is Weak ETags
'modified'=> $mdate,// (here, $mdate is Unix timestamp)
'expiry'=> 3600// set expiry date 1 hour from time()
);
$Encode= new Conteg( $param );
* My pages are all .htm/.html but I set them up to parse as php ... Do you have any walk through instructions for a newbie to implement that?
If I do not want to use compression would this be correct? :
* ------------Start of file---------------
<?php
include('Conteg.inc');
$param= array(
'use_etag'=> TRUE,// default is Weak ETags
'modified'=> $mdate,// (here, $mdate is Unix timestamp)
'expiry'=> 3600// set expiry date 1 hour from time()
);
$Encode= new Conteg( $param );
?>
--rest of page goes here (all pages are .htm/.html and I parse them as .php which is why I need this in the first place)
* -------------End of file----------------
Thanks for all your help!
This message [webmasterworld.com] has precisely what you require.
Add:
'use_accept_encode' => FALSE,
Everything is clear as day to me now... just a simple prepend and append called in htaccess with the correct files I throw on the server.
Quick question though, my pages (while parsed in php) are basically static and do not change much at all. Would you still recommend compression in this case? Is there a great downside to one over the other I should be concerned about? I am talking about sites with about 400 or so pages on each which rarely change.
Again, thank you for your help and the amazing script!
Quick question though, my pages (while parsed in php) are basically static and do not change much at all. Would you still recommend compression in this case?
Current AWStats figures for my .co.uk site (almost entirely static, unchanging .html pages, processed exactly the same as your own) show an *average* compression of 81% (829.08 MB reduced to 156.97 MB for January). That's better than a 5-fold reduction. That means that the page arrives 5 times faster than it normally would. Even ignoring the faster (client) computers available nowadays, that means a much faster display, since--usually--the page can start to be de-compressed whilst later chunks are arriving and, as long as your page is written correctly, that means that the top of the page can be displayed whilst later chunks are still being dispatched.
Turning to php-originated pages, I have to confess--to my shame--that I have a page that is more than 500 KB on my .com site. Because of large-scale duplication of HTML code on that page, it shrinks by better than 90%. That means a 50k page rather than half-a-megabyte, which is a much more reasonable proposition. For the same reason, my admin pages can approach 95% reduction.
Finally, the compression is load-balanced, which means that the server is never compromised by the extra load required.
You will, perhaps, have gotten the point that I am a complete fan of file-compression.
I set the expires for a full day (86400), but the header always shows one hour in the future. Is this something I need 12.3 for?
That is the precise bugfix in v0.12.3 cf v0.12.2.
v0.12.3 will cost you £1 GBP (covers my bandwidth charges). However, if you are a complete miser (no disrespect intended - that phrase neatly describes myself) you will find the changes required within the "Site Info & Diary" forum on my site; just search for "Conteg".
My last and final question, I promise... I used the liveheaders extension in firefox to test results after I implemented this... I noticed that language (en) and encoding (iso 8859-1) are sent as well with the conteg. Does this mean I can remove those headers from my pages and will receive no ill affect? For SEO reasons even?
For instance, here is an example head portion of one of my static htm pages (yet parsed as php and using conteg) :
<html>
<head>
<title>About my site</title>
<meta name="description" content="my site desc">
<meta name="keywords" content="my, keywords">
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<meta http-equiv="Content-Language" content="en-us">
<meta name="ROBOTS" content="ALL">
<meta name="Rating" CONTENT="General">
<link href="style.css" rel="stylesheet" type="text/css">
</head>
language (en) and encoding (iso 8859-1) are sent as well ... Does this mean I can remove those headers from my pages and will receive no ill affect?
General reply:
The short answer is "Yes, but make sure that the server-headers match reality".
Personally, I'm a strong believer in 'Belt 'n' Braces', so if in doubt, send both. If browsers were perfect, that would not be necessary, but they most certainly are not. However, you will need to take steps to make sure that they are all--server-headers, page-headers & document--identically the same.
Specific reply:
Beware that this specific header is reported to cause some browsers to redraw the page after initially displaying it.
The
<meta http-equiv ... />statement has a specific intention. It is designed to provide a means for those with either no access to the web-server config, or otherwise to make it simple, to instruct the server to deliver up specific HTTP headers (& inform browsers that can understand it as a fall-back). In other words:
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">means to those servers that can, and are configured to implement it:
"send a Content-Type: HTTP header with this value"
<html lang='en-us'> However, more important than all this is: is it all consistent?
In other words, consider:
<html lang= ...>element.
<meta http-equiv='Content-Type' ... />element.
If not, then you can bet that it will turn round and bite you on the bum. Google uses dozens of different parameters to score a page these days, and --although I have no specific info--I cannot believe that both the existence of Content-Type info, and it's consistency, are not among those parameters.
<?php
new Conteg( array(
'modified'=> filemtime($_SERVER['SCRIPT_FILENAME']),
'use_etag'=> TRUE,
'expiry'=> 86400,
'cache_control' => array(
'macro' => 'cache-all'
)
));
?>
So with that said, this sends the cache-control public with maxage and s-maxage at 86400 (one day). I'd like to use this to increase customers browsing speed just that little bit more by taking advantage of shared caches.
I guess my concern with this is for authenticated pages. For instance, I just viewed the headers on an auth page and it will be public which I definately do not want. Conteg over rides the deault headers sent in that protected directory.
On the other hand, I could also add 'no-cache' which would make the authentication sent before releasing the cached version, but then the catch 22 is it wil set that for every page including non-auth ones which I do not want either.
Is there a work around for this when using conteg?
(cache-control) ... I guess my concern with this is for authenticated pages
paramparameter in either the Conteg constructor or, perhaps, a later
setup()call.
Cache-Control Macros:
I like as easy a life as possible, hence the 'cache-all' and 'no-cache' macros. You can, however, get as fine-grained control as you want, since *every* Cache-Control element can be set individually. There is also nothing to stop you from implementing your own macros - if you find some that you think are particularly useful in particular circumstances, pass them along.