PHP Classes
elePHPant
Icontem

File: example_1.php

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Classes of Jacek Wloka  >  cache_TS  >  example_1.php  >  Download  
File: example_1.php
Role: Example script
Content type: text/plain
Description: example 1
Class: cache_TS
Cache the output of PHP script in files
Author: By
Last change: the catalogue cache has to have chmod 666 or 777
Date: 8 years ago
Size: 2,166 bytes
 

Contents

Class file image Download
<?php

/* the catalogue cache has to have chmod 666 or 777 */


/*========================*\

 * cache_TS
 * Written by: AS
 * Mialto: as@twoja-strona.net
 * Date: 2007-08-23
 * Cache: multiSystem cache SQL and PHP code
 * Version: 1
 * Licencia: Lesser General Public License (LGPL)
 *
 * Copyright (C) 2007 Jacek Wloka
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.

\*========================*/

function getmicrotime(){
    list(
$usec, $sec) = explode(" ",microtime());
    return ((float)
$usec + (float)$sec);
}


include (
'cache_ts.php');

$cache = &new cache_TS();

// the question test 1
$q = 'loop for 1000000 test1';

$time_start = getmicrotime();

/******************************************************************************\

  check_cache('question_ID or the question of sql', second=300, dir='./cache')

\******************************************************************************/

if ($cache->check_cache($q))
{
   
$cache->start_cache();

    for (
$i=1; $i<1000000; $i++) {
         echo
$i.'-';
    }

   
$cache->end_cache();
}
 else
{
   
$cache->contents_cache();
}


$time_end = getmicrotime();
$time = $time_end - $time_start;
echo
'<hr /><br />Test 1 Generate in '.$time.' s. <a href="?">refresh</a>';

/******************************************************************************\

  // the question test 2

\******************************************************************************/

echo '<hr /><br />';

$q = 'loop for 255 test2';

$time_start = getmicrotime();

if (
$cache->check_cache($q))
{
   
$cache->start_cache();

    for (
$i=1; $i<255; $i++) {
         echo
chr($i).'-';
    }

   
$cache->end_cache();
}
 else
{
   
$cache->contents_cache();
}


$time_end = getmicrotime();
$time = $time_end - $time_start;
echo
'<hr /><br />Test 2 Generate in '.$time.' s. <a href="?">refresh</a>';

?>