PHP Classes
elePHPant
Icontem

File: APC_test.php

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Classes of Eper Kalman  >  APC_handler  >  APC_test.php  >  Download  
File: APC_test.php
Role: Example script
Content type: text/plain
Description: example script
Class: APC_handler
Store session data in MySQL and in memory with APC
Author: By
Last change:
Date: 3 years ago
Size: 1,680 bytes
 

Contents

Class file image Download
<?php

   
include_once('APC_handler.class.php');

   
$start=microtime(true);

   
$session = new APC_handler();

       
// $session->reset();
        // $session->no_apc();
        // $session->keep_base_on_restart();

   
$session->mysql_connect ('host', 'user', 'password');
   
$session->mysql_base('temp', 'sessions', 'loggeds');
   
$session->expire(5); // minutes
   
$session->keep_free(10); // MB
   
   
$session->set_session_handler();
   
   
// get the connection if not want
    // to make more (persistent)
   
$mysqli=$session->get_connection();

   
/**
        // Uncheck to test functionality when system is highly loaded
        // the value 118 change to your settings of max apc shared memory
        // overloading memory may have unexpected results

        $MB='';
        for ($i=0; $i<(1024*1024); $i++) {
            $MB.='a';
        }

        for ($i=0; $i<118; $i++) {
            apc_store("SX$i", $MB, 0);
        }
    **/

   
session_id(md5('user'));

   
session_start();

   
/**
         // uncheck to test copy to base and back

        $session->mem2base();
        $session->base2mem();
    **/
   
   
$SID=$session->is_logged('user');

    if (!
$SID) {

        echo
'<br>User is not logged (session expired or logged out).';
       
$session->login('user');
    } elseif ((
$SID) && ($SID!=session_id())) {

        echo
"<br>User is logged once with id:$SID.";
    } else {

        echo
"<br>User is logged with current session id.";
    }

    if (! isset(
$_SESSION['check'])) {

        echo
'<br>Session is expired or first time is created.';
       
$_SESSION['check']=1;
       
    } else {

        echo
'<br>Session check passed ($_SESSION[\'check\']='.$_SESSION['check'].').';
    }

   
// $session->logout('user');

   
$end=microtime(true);

    echo
'<br>Session & user login checked in '.round(($end-$start),6) .' s.';
   

   
//session_destroy();

?>