[Chameleon] using ob_start with Chameleon

Bart van den Eijnden BEN at Syncera-ITSolutions.NL
Thu Jul 21 04:31:02 EDT 2005


Hi list,

I have just spent the last hour or so trying to get ob_start to work in conjunction with Chameleon, it was more trying to figure out the right place to put it. So I thought I'd share my experiences.

For people who do not know what ob_start is, it can compress your HTML content in an output buffer, for my Chameleon site it changed from 120 Kb to 22 Kb for the main HTML output send by Chameleon!

I added ob_start to the index.phtml file of the application, so I did not need to change the Chameleon core, ie:

<?php
/*
 * this is a sample of a minimal application script required to
 * get a chameleon application running with a template and a
 * local map file.  Most applications should actually just
 * copy this file and modify the template and mapfile
 * parts and should not need to do a lot more here.
 */
include( "../../common/chameleon/htdocs/chameleon.php" );

ob_start("ob_gzhandler");

// set the language to Dutch
$_SESSION['gszCurrentLanguage'] = 'nl-NL';
$_SESSION['gszDefaultLanguage'] = 'nl-NL';

$szTemplate = "./stragisweb.html";
$szMapFile = "map/stragisweb.map";

// deduct site name from the URL
$szURL = dirname( $_SERVER['PHP_SELF'] );
$iPos = strrpos ($szURL, '/');
$szSiteName = substr($szURL, $iPos+1, strlen($szURL));

class SampleApp extends Chameleon
{
  function SampleApp()
  {
    parent::Chameleon();
    $this->moMapSession = new MapSession_RW;
    $this->moMapSession->setTempDir( getSessionSavePath());
  }
}

$oApp =  new SampleApp();

$oApp->registerSkin( 'skins/stragisweb' );
$oApp->CWCInitialize( $szTemplate, $szMapFile  );
$oApp->mnMinimumMaturityLevel = MATURITY_ALPHA;
$oApp->setVar( "gszAppWebPath", $_SESSION['gszAppWebPath'] );
$oApp->setVar( "gszCoreWebPath", $_SESSION['gszCoreWebPath'] );
// pass site name to the HTML template
$oApp->setVar( "gszSiteName", $szSiteName ); 
$oApp->setVar( "SID", sid ); 
$oApp->CWCExecute( array( '../../common/widgets' ) );

ob_end_flush();

?>

At the end of the script you call ob_end_flush(); to send everything at once to the browser.

Hope this helps.

Best regards,
Bart

Bart van den Eijnden
Syncera IT Solutions
Postbus 270
2600 AG  DELFT

tel.nr.: 015-7512436
email: BEN at Syncera-ITSolutions.nl




More information about the Chameleon mailing list