Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re: Best way of storing semi-static data

by freddo411 (Chaplain)
on Dec 23, 2004 at 02:07 UTC ( [id://416979]=note: print w/replies, xml ) Need Help??


in reply to Best way of storing semi-static data

Since you mention this is on your main page, it sounds like you are worried a bit about performance. A static page is much faster than a page that requires a DB lookup, however, some web server setups already incur much of the expense of establishing a DB connection so the "cost" might not be so high; it depends on your particular circustances. Let's assume that the choice is between a static page and the full cost of establishing a DB connection and quering the DB for the info.

You can build a semi-static site quite easily. Use HTML::Template (or other templating module) to merge semi-static db data into static .html files. Psuedo code below: (note this does one file, but you could easily do many with this same script )

use HTML::Template my %vars = getStuffFromDB(); # open the html template my $t = HTML::Template->new(filename => 'ffff.tmpl'); $t->param( foo => $var{'foo'}; # open $filehandle to .html file .. snip .. # output print $fh $t->output;

-------------------------------------
Nothing is too wonderful to be true
-- Michael Faraday

Replies are listed 'Best First'.
Re^2: Best way of storing semi-static data
by kiat (Vicar) on Dec 23, 2004 at 14:08 UTC
    Thanks, freddo411!

    That's the kind of solution I'm having. At this point in time, performance isn't a problem because the traffic to the site is low. But I'm not certain whether performance will take a dip when more people are simultaneously on the site.

      As suggested above by yacoubean, to complete the solution you can have the "makeHTML.pl" script run nightly to make sure that your static page is up to date. Obviously you can set this update interval to any time period you like. Even if you do it as often as hourly your users will enjoy the benefit of a very fast static page.

      On Unix the scheduler is called "cron" and the schedule to run things is called a crontab. The command crontab -e will allow you to edit your personal crontab entries. You'll want to set up an ENV var for your visual editor before you run crontab -e (read the man page for details).

      Merrry Xmas

      -------------------------------------
      Nothing is too wonderful to be true
      -- Michael Faraday

        I just checked that the shared server I'm using allows crons. The minimum interval for a cron job is every one hour. I might be able to use that. Thanks and Merry Xmas :)

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://416979]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (5)
As of 2024-04-19 02:34 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found