Modem-Help Forum Index Main Site
Modems
Downloads
Chips, Chipsets
Help [ Old Help ]
SearchAbuseAggregatorEFG
Modem-Help
Dedicated help on Modems
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Conteg.include v0.10 PHP Class : Documentation : Overview

 
Post new topic   Reply to topic    Modem-Help Forum Index -> Site Info + Diary
View previous topic :: View next topic  
Author Message
Alex Kemp
Site Admin


Joined: 30 Jun 2004
Posts: 6033
Location: Nottingham, England

PostPosted: Tue Sep 20, 2005 3:51 am    Post subject: Conteg.include v0.10 PHP Class : Documentation : Overview Reply with quote

Site Updated to use HTTP/1.0 Request Headers
Site Updated to use HTTP/1.1 Response Headers
Conteg.include v0.10 PHP Class : Documentation : Overview
Conteg.include v0.10 PHP Class : Documentation : ETags
Conteg.include v0.10 PHP Class : Docs : External Negotiation
Conteg.include v0.10 PHP Class : Documentation : Miscellany


Conteg.include - a PHP Class for Content Auto-Negotiation
Code:
 *  Content-Negotiation 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.


Simple deployment - auto-negotiates page Compression only

The 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.
Code:
<?php
   ob_start();                // <==== line 1
   include('Conteg.include'); // <==== line 2

   ... the page ...

   new Conteg();              // <==== line 3
?>


Simple HTTP/1.0 deployment - auto-negotiates page Compression + If-Modified-Since

The simplest possible http/1.0 usage requires a change to line#3:
Code:
<?php
   ob_start();                // <==== line 1
   include('Conteg.include'); // <==== line 2

   ... the page ...

   new Conteg( array(
      'modified' => strtotime( $mdate ), // (string) default is time()
      'expiry'   => 864000               // set expiry date 10 days from now
   ));                                   //+default is 1 hour
?>

...which neatly introduces the parameter-array which can be supplied for the constructor. The full array--with supplied defaults--is below, and is documented in following posts but first, how to instantiate the Class without immediately printing out the page contents:
Code:
<?php
   ob_start();                // <==== line 1
   include('Conteg.include'); // <==== line 2
   $Encode = new Conteg(      // <==== instantiation
      array(
         'noprint' => TRUE
      )
   );

   ... the page ...

   $Encode->setup( array(
      'charset'  => 'ISO-8859-1',
      'lang'     => 'en',
      'modified' => strtotime( $mdate ),
      'type'     => 'text/html'
   ));
   $Encode->show();
?>

The default action for the Class is to print the ob-buffer contents to stdout immediately on instantiation (which is why, by default, it needs to be on the last line of the program). That will auto-negotiate Accept-Encoding (compression) but not media-type (Accept) nor Accept-Charset. If you want to negotiate these latter 2 within a program, or to select a different page language (the program does not negotiate language, which could involve sending a 406 Not Acceptable, but does send a Response header reporting the language used) it will be necessary to use the template above.

All Content-Negotiation is delayed until Conteg::show(), so most setup can be performed at any time and as often as required. The exception is the noprint parameter, which applies only to the Constructor.


Simple HTTP/1.1 deployment - auto-negotiates Accept-Encoding, If-Modified-Since, If-Unmodified-Since, If-None-Match

The simplest possible http/1.1 usage requires a change to line#3:
Code:
<?php
   ob_start();                // <==== line 1
   include('Conteg.include'); // <==== line 2

   ... the page ...

   new Conteg( array(
      'use_etag' => TRUE,     // default is Weak ETags
      'modified' => $mdate    // (timestamp) default is time()
   ));
?>
The ETag used will be reliably auto-constructed within the Class. This specific usage does not allow the use of Ranges.


Constructor Array Parameter - also used by setup()

Conteg::Conteg constructor parameter with defaults:
Code:
<?php
   $Encode = new Conteg(
      array(
         'charset'            => 'ISO-8859-1',
         'encodings'          => array( 'gzip','deflate','compress' ),
         'etag'               => '',
         'expiry'             => 3600,       // seconds (added to time())
         'input'              => 'instream',
         'lang'               => 'en',
         'modified'           => NULL,       // (timestamp) default is time()
         'noprint'            => FALSE,      // constructor only
         'output'             => 'outstream',
         'prefer'             => array(),
         'ratio'              => 'ratio',
         'search'             => array(),
         'type'               => 'text/html',
         'use_accept'         => FALSE,
         'use_accept_charset' => FALSE,
         'use_accept_encode'  => TRUE,
         'use_accept_lang'    => FALSE,
         'use_accept_ranges'  => FALSE,
         'use_apache_notes'   => FALSE,
         'use_content_lang'   => TRUE,
         'use_content_type'   => TRUE,
         'use_etag'           => FALSE,
         'weak_etag'          => TRUE
      )
   );
?>
They are documented within following posts.

2009-04-16 Edited by AK
Edit Reason: Fixed URLs

_________________
Alex Kemp
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    Modem-Help Forum Index -> Site Info + Diary All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2007 phpBB Group