Welcome to WebmasterWorld Guest from 54.196.231.129

Forum Moderators: coopster & jatar k & phranque

Message Too Old, No Replies

Caching pages with Perl

Need to store frequently accessed pages

     
6:18 pm on Aug 12, 2004 (gmt 0)

Junior Member

10+ Year Member

joined:Nov 20, 2003
posts:50
votes: 0


Hello, I need to cache pages in my server to reduce server load. I currently implemented the following script in my php pages and need to do the same with PERL

<?php
$cachefile = "cache/".$title.".html";

if (file_exists($cachefile))
{ include ($cachefile);
exit();
}

ob_start();
?>

Page with html and database here

<?php
$buffer = ob_get_contents();
$fp = fopen($cachefile, 'w');
fwrite($fp, $buffer);
fclose($fp);
?>

This script checks if the cached page exists and shows it instad of executing the rest of the page.

But if the page does not exist, then it opens a buffer and saves all the output into a page. It writes the page into the server so the next time it is called.

How can I do that in Perl. I have a script that consumes a lot of resources. If possible, I would like to place it before it calls the script, but that would involve passing variables through one script to another.

Is there an easy way to do so?

Thanks in advance

Enrique

6:20 pm on Aug 13, 2004 (gmt 0)

Junior Member

10+ Year Member

joined:July 17, 2004
posts:73
votes: 0


Use the Storable module and check if the file exists (as you did in your php script). Works like a champ and is fast even on my celeron 500.
6:28 pm on Aug 13, 2004 (gmt 0)

Preferred Member

10+ Year Member

joined:Oct 28, 2002
posts:492
votes: 0


Have a look at Cache::Cache and Cache::FileCache. There are many more Cache::XXXCache classes that store cached data in different ways (files, shmem, ...).

René