homepage Welcome to WebmasterWorld Guest from 54.226.173.169
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Pubcon Platinum Sponsor 2014
Home / Forums Index / Code, Content, and Presentation / Perl Server Side CGI Scripting
Forum Library, Charter, Moderators: coopster & jatar k & phranque

Perl Server Side CGI Scripting Forum

    
Caching pages with Perl
Need to store frequently accessed pages
Eugenios




msg:438314
 6:18 pm on Aug 12, 2004 (gmt 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

 

kalos




msg:438315
 6:20 pm on Aug 13, 2004 (gmt 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.

seindal




msg:438316
 6:28 pm on Aug 13, 2004 (gmt 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é

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / Perl Server Side CGI Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved