in reply to pulling content from db - is it a good idea?

I not sure whether you mean:

• you want to store the content, and not the HTML in this database, or...
• you want to store both in the database

In either case (thought not so sure you'd want to try the latter), what you are proposing is nothing new. In fact, unless I'm not reading correctly between the lines, you are talking about a database-driven content management system (to make it sound important). This is the underlying structure for more and more Web sites, and is the future.

Before joining the order of Perl Monks, I used to store all content in flat files, and HTML in the Perl scripts that would pull the content from the files and then render the HTML pages as "here documents."

Well, those days are gloriously over. Thanks to HTML::Template and MySQL. The latter makes content storage and retrieval nice and tidy, and HTML::Template allows you to build and maintain standalone HTML pages with placeholders for the content to come later. Perl scripts pull content from the database and H::T renders the HTML page with the content inserted.

Of course, you will need to supply a GUI for your users (can be done through something as simple as HTML forms or as complicated as the Microsoft DHTML Editing Component).

I hope I got what you were asking, it's just that the practice is so common today that I thought I might have missed the point of your question. Apologies if I did, and write on if I didn't.

—Brad
"A little yeast leavens the whole dough."
  • Comment on Re: pulling content from db - is it a good idea?

Replies are listed 'Best First'.
Re: Re: pulling content from db - is it a good idea?
by swngnmonk (Pilgrim) on Nov 26, 2003 at 04:50 UTC

    It's funny how everything goes around in circular fashion. When I started doing web development, servers didn't have much in the way of capacity, and CGIs were extremely expensive, so everything was static. Dynamic content was something reserved for a small section of the site, and generally served off a different machine (as I remember, we had some big 8-processor Sun boxes for this - heck, it was 1996).

    As time went on, the software improved, more features were desired, and dynamic content started to creep into more areas of out sites. Our front-line webservers started serving quasi-dynamic content, and those 8-processor boxes went by the wayside.

    Nowadays, we're almost back where we started. We have front-line webservers that do nothing except serve static HTML, though we do use mod_include SSI directives as well (something that could be done in perl). We generally don't do much in dynamic content, except for full-blown applications. And we serve a *lot* of content every day.

    With all that - nothing beats static HTML in terms of performance or server response time. And the more systems/applications you add to a page, the fewer pages you're able to serve, the more your response time goes up, and the more hardware you'll need to support your site.

    Things to think about:

    • Serve static HTML. If you've got dynamic components, how often do they need to update? Do they need to update on every request? If not, that's not dynamic - it's static that just needs to change often - the data can probably be written out to the filesystem and included in the page in any number of ways.
    • If you need dynamic content on every page - use HTML::Template, it's the fastest templating system for perl out there. And look into caching your templates, it will save a lot of memory in a server environment. Screw 'more powerful' templating systems - HTML::Template does anything you'll need, and it won't slow you down. I've never been in a situation where it hasn't done what I need.
    • Minimize the amount of content that needs to be re-written. If you're talking about sidebar content, don't re-write the main body at all! Save it elsewhere and slurp it in!
    • KEEP THE DB AWAY FROM THE FRONT LINE! Nothing slows a site down like hitting a database - even if you're caching your DB connections, you're talking about a whole other application that you're interacting with. Get a lot of traffic, and your DB will be holding you back.
    • If you absolutely need to hit a data store on every single page, what can you do to speed it up? Can you pre-load all the data from the DB before you start serving connections? Can you use a BerkleyDB?

    I don't want to discourage you from going into dynamic website construction - it's where things get interesting. But if you're not careful, you can find yourself with a server melting down under the load, and few quick remedies. Try a few things, see what it gets you, but keep the above in mind if people start to really like what you're doing. Good luck! :)

Re: Re: pulling content from db - is it a good idea?
by kiat (Vicar) on Nov 25, 2003 at 13:25 UTC
    Thanks, Brad!

    I was referring to storing just the content (minus the html) in the database.

    To reiterate your points: It's pretty the normal thing to do these days to store content in the database and have a perl script pull out the content and display it via HTML:Template.

    Is that right?

      Yup, common as dirt. There are several Tutorials here at the Monastery. Here's a taste of how it works:

      The HTML (has to be saved with .tmpl extension):
      <tr> <td><span class="header"> <!-- placeholder --> <tmpl_var name=listfor>'s List </span> </td> </tr> <tr> <td> <!-- placeholder --> <tmpl_var name="list"> </td> </tr>
      The Perl:
      use HTML::Template; #tell H-T what page to display $template = HTML::Template -> new(filename => "displaylists.tmpl"); + #connect to DB, SELECT, etc. then... @data = $sth->fetchrow_array(); #assign data to placeholders $template ->param(listfor => $data[1], list=> $data[2]); print "Content-type: text/html\n\n"; print $template->output; #display html
      It's pretty easy once you get the hang of it. And the HTML designers will appreciate not having their design packed away in some Perl script.

      —Brad
      "A little yeast leavens the whole dough."