PHP Classes

File: examples/builtin.php

Recommend this page to a friend!
  Classes of Colin McKinnon   Stackable PHP Session Handler   examples/builtin.php   Download  
File: examples/builtin.php
Role: Example script
Content type: text/plain
Description: Using the builtin handler (for baseline)
Class: Stackable PHP Session Handler
Store session data with multiple session handlers
Author: By
Last change:
Date: 8 years ago
Size: 1,195 bytes
 

Contents

Class file image Download
<?php
require_once('utils.inc.php');

logger("started");
logger("* about to call session_start()");

session_start();

if (!isset(
$_SESSION['c'])) $_SESSION['c']=0;

if ((integer)
$_SESSION['c'] && !($_SESSION['c'] % 3)) {
   
logger("* about to regenerate");
   
session_regenerate_id();
}
++
$_SESSION['c'];
logger("about to finish");
session_write_close();
?>
<html>
<H1>The Built In Handler</H1>
<p>
This script is here to give you an idea of how the performance
of the custom handlers compares with the buit in handler.
</p><p>
Running this on a test machine, not doing much else, and you'll probably be disappointed, though not very surprised
to find that the builtin handler is a lot faster (around 6 times faster on the machine I'm typing this on) than
the custom handlers. But when the traffic volumes ramp up and compete with more meaningful transactions, you'll
see a performance advantage using the nonblocking and/or writeSometimes handlers (remember, you can use both!).
<br />
We can't inject a debug logger into the script so the details below only show what is happening outside the handler:<br />
<?php
print "OK:++\$_SESSION['c']=" . $_SESSION['c'] . "<pre>$statuslog</pre>";
exit;