Using Pear Cache
| From: | Andreas Otto | Date: | Mon, 24 Dec 2001 23:11:37 +0000 |
| Subject: | Using Pear Cache | ||
| Groups: | php.pear.general | ||
| Request: | Send a blank email to pear-general+get-631@lists.php.net to get a copy of this message | ||
Hi all and Merry Christmas,
I just came across a quite strange behaviour while trying to use the Pear
Chache.
Every file I call will display will display the content of the first file I
have called.
E .g. file 1 ouputs "Hello World" and file 2 outputs "Hello Andreas". If I
call file 1 for the first time, the ouput is the expected "Hello World" if I
call file 1 a second time the expected output is again "Hello World". But if
I call file 2 now the ouput is "Hello World" as well which seems a bit odd to
me.
Since the Pear Cache is working for other people I must have done something
wrong. I would therfore very much appreaciate it if someone could have a look
at the two attached examples.
Cheers,
Andreas
--
Andreas Otto <a-otto@web.de>
Using PHP on Windows? www.php4win.de
<?php require_once "Benchmark/Timer.php"; /** Settings for benchmarking */ define ("BENCHMARK", true); if (BENCHMARK){ $timer = new Benchmark_Timer; $timer->start(); } /** Start PEAR Cache */ require_once("Cache/Output.php"); define ("CACHE_STORAGE_CLASS", "file"); define ("CACHE_DIR", "/usr/local/httpd/test/tmp/"); define ("CACHE_FILENAME_PREFIX", "cache_"); $options = array( "cache_dir" => CACHE_DIR, "filename_prefix" => CACHE_FILENAME_PREFIX ); $cache = new Cache_Output (CACHE_STORAGE_CLASS, $options); $id = $cache->generateID( array( "uri" => $REQUEST_URI, "post" => $HTTP_POST_VARS, "cookie"=> $HTTP_COOKIE_VARS ) ); if ($content = $cache->start($id)) { print $content; /** Stop benchmark */ if (BENCHMARK){ $timer->stop(); printf ("<p>Cache hit: %s</p>", $timer->timeElapsed()); } die("Script execution stopped."); } ?> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN"> <html> <head> <title>[phpa]</title> </head> <body> <p> <?php for ($i = 1; $i <= 100; $i++){ printf ("%s, ", $i); } ?> </p> <p><a href="page02.php">page02.php</a></p> </body> </html> <?php /** End PEAR Cache */ $cache->endPrint(60, __FILE__ . " " . filemtime(__FILE__)); /** Stop benchmark */ if (BENCHMARK){ $timer->stop(); printf ("<p>Cache miss: %s</p>", $timer->timeElapsed()); } ?> <?php require_once "Benchmark/Timer.php"; /** Settings for benchmarking */ define ("BENCHMARK", true); if (BENCHMARK){ $timer = new Benchmark_Timer; $timer->start(); } /** Start PEAR Cache */ require_once("Cache/Output.php"); define ("CACHE_STORAGE_CLASS", "file"); define ("CACHE_DIR", "/usr/local/httpd/test/tmp/"); define ("CACHE_FILENAME_PREFIX", "cache_"); $options = array( "cache_dir" => CACHE_DIR, "filename_prefix" => CACHE_FILENAME_PREFIX ); $cache = new Cache_Output (CACHE_STORAGE_CLASS, $options); $id = $cache->generateID( array( "uri" => $REQUEST_URI, "post" => $HTTP_POST_VARS, "cookie"=> $HTTP_COOKIE_VARS ) ); if ($content = $cache->start($id)) { print $content; /** Stop benchmark */ if (BENCHMARK){ $timer->stop(); printf ("<p>Cache hit: %s</p>", $timer->timeElapsed()); } die("Script execution stopped."); } ?> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN"> <html> <head> <title>[phpa]</title> </head> <body> <p> <?php for ($i = 101; $i <= 200; $i++){ printf ("%s, ", $i); } ?> </p> <p><a href="index.php">index.php</a></p> </body> </html> <?php /** End PEAR Cache */ $cache->endPrint(60, __FILE__ . " " . filemtime(__FILE__)); /** Stop benchmark */ if (BENCHMARK){ $timer->stop(); printf ("<p>Cache miss: %s</p>", $timer->timeElapsed()); } ?>
<?php require_once "Benchmark/Timer.php"; /** Settings for benchmarking */ define ("BENCHMARK", true); if (BENCHMARK){ $timer = new Benchmark_Timer; $timer->start(); } /** Start PEAR Cache */ require_once("Cache/Output.php"); define ("CACHE_STORAGE_CLASS", "file"); define ("CACHE_DIR", "/usr/local/httpd/test/tmp/"); define ("CACHE_FILENAME_PREFIX", "cache_"); $options = array( "cache_dir" => CACHE_DIR, "filename_prefix" => CACHE_FILENAME_PREFIX ); $cache = new Cache_Output (CACHE_STORAGE_CLASS, $options); $id = $cache->generateID( array( "uri" => $REQUEST_URI, "post" => $HTTP_POST_VARS, "cookie"=> $HTTP_COOKIE_VARS ) ); if ($content = $cache->start($id)) { print $content; /** Stop benchmark */ if (BENCHMARK){ $timer->stop(); printf ("<p>Cache hit: %s</p>", $timer->timeElapsed()); } die("Script execution stopped."); } ?> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN"> <html> <head> <title>[phpa]</title> </head> <body> <p> <?php for ($i = 1; $i <= 100; $i++){ printf ("%s, ", $i); } ?> </p> <p><a href="page02.php">page02.php</a></p> </body> </html> <?php /** End PEAR Cache */ $cache->endPrint(60, __FILE__ . " " . filemtime(__FILE__)); /** Stop benchmark */ if (BENCHMARK){ $timer->stop(); printf ("<p>Cache miss: %s</p>", $timer->timeElapsed()); } ?> <?php require_once "Benchmark/Timer.php"; /** Settings for benchmarking */ define ("BENCHMARK", true); if (BENCHMARK){ $timer = new Benchmark_Timer; $timer->start(); } /** Start PEAR Cache */ require_once("Cache/Output.php"); define ("CACHE_STORAGE_CLASS", "file"); define ("CACHE_DIR", "/usr/local/httpd/test/tmp/"); define ("CACHE_FILENAME_PREFIX", "cache_"); $options = array( "cache_dir" => CACHE_DIR, "filename_prefix" => CACHE_FILENAME_PREFIX ); $cache = new Cache_Output (CACHE_STORAGE_CLASS, $options); $id = $cache->generateID( array( "uri" => $REQUEST_URI, "post" => $HTTP_POST_VARS, "cookie"=> $HTTP_COOKIE_VARS ) ); if ($content = $cache->start($id)) { print $content; /** Stop benchmark */ if (BENCHMARK){ $timer->stop(); printf ("<p>Cache hit: %s</p>", $timer->timeElapsed()); } die("Script execution stopped."); } ?> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN"> <html> <head> <title>[phpa]</title> </head> <body> <p> <?php for ($i = 101; $i <= 200; $i++){ printf ("%s, ", $i); } ?> </p> <p><a href="index.php">index.php</a></p> </body> </html> <?php /** End PEAR Cache */ $cache->endPrint(60, __FILE__ . " " . filemtime(__FILE__)); /** Stop benchmark */ if (BENCHMARK){ $timer->stop(); printf ("<p>Cache miss: %s</p>", $timer->timeElapsed()); } ?>