Publishing dynamic pages to flat HTML

Click For Summary

Discussion Overview

The discussion centers around the challenge of generating static HTML pages from a database-driven portal, with a focus on efficiency and performance. Participants explore various methods for publishing dynamic content to flat HTML, considering the balance between dynamic generation and static serving.

Discussion Character

  • Exploratory
  • Technical explanation
  • Debate/contested
  • Mathematical reasoning

Main Points Raised

  • One participant suggests generating HTML pages from a database only when changes occur, proposing that using Perl might be a solution.
  • Another participant proposes caching data as a simpler alternative to writing files, but acknowledges concerns about reliability.
  • A participant emphasizes that any programming language can be used to generate HTML, noting that performance is less critical since the process is infrequent and local.
  • One participant describes their current setup with PHP/MySQL, highlighting slow load times and the desire for a faster, flat HTML solution that integrates with their web-based control panel.
  • Another participant agrees that PHP is a suitable choice for generating HTML files and discusses the possibility of redirecting PHP output to files instead of the browser.
  • Concerns are raised about the efficiency of accessing the database multiple times for the same data, especially in the context of shared SQL server limitations.
  • A detailed method is proposed for converting PHP pages to HTML by making HTTP requests to the local server and saving the output, allowing for future flexibility.

Areas of Agreement / Disagreement

Participants express varying opinions on the best approach to generating static HTML pages. While some advocate for using PHP, others suggest caching or different programming languages. The discussion does not reach a consensus on a single solution.

Contextual Notes

Participants mention potential limitations related to performance, reliability of caching, and the need for web-based administrative operations. The discussion reflects a range of assumptions about the technical environment and user needs.

Who May Find This Useful

Web developers and system administrators interested in optimizing the performance of database-driven websites, particularly those looking to implement static HTML generation methods.

DaveC426913
Gold Member
2025 Award
Messages
24,475
Reaction score
8,739
I want to be able to generate pages from a database but the data only changes occasionally. It'd be more efficient to have the pages served up from flat HTML most of the time and only have to "publish" to HTML when I make a change to the database.

Is there a really convenient way of doing this? PERL's the trick, isn't it?
 
Technology news on Phys.org
Could you cache the data? Seems less hassle than writing files out.
 
verty said:
Could you cache the data? Seems less hassle than writing files out.

Well, caching isn't exactly reliable. And it's not exactly going to work reliably for my users.
 
You can pretty much use any language you want to generate the html, anything at all. It doesn't have to run inside the web server, so you're not limited to server-side languages. Also since this will be run only so often, only locally, and only by you, performance isn't much of a factor either.
The only thing you have to consider is whether in the future you might find yourself having to update the content so often you have to go back to dynamically generated pages.
 
-Job- said:
You can pretty much use any language you want to generate the html, anything at all. It doesn't have to run inside the web server, so you're not limited to server-side languages. Also since this will be run only so often, only locally, and only by you, performance isn't much of a factor either.
The only thing you have to consider is whether in the future you might find yourself having to update the content so often you have to go back to dynamically generated pages.

I'm not sure you're getting what I'm after.

What I have:
Currently, my portal is built in PHP/MySQL. Every time I access my portal, the PHP has to build it from scratch and deliver it to me. It takes 5-20 seconds or more. If I want to make a change, I have a web control panel right there on my page where I make edits and then save.

What I want:
I want to have my portal on a flat HTML page, so it loads fast. When I want to add a link, I go to my web control panel and make the change, which is saved to the db. This db save triggers some app that writes a new HTML page, so that my portal when I go to it now has the new content.

The key here, is that my portal admin operations must all be web-based. I might not be at my home computer when I want to add a new link. I won't have any files, I won't have an ftp app, I won't have any editor (except the web-based one I've built).
 
Last edited:
You can still use anything you want, because you can have a PHP script start your HTML writer app. Of course since you have PHP available i would just use PHP.
Your PHP script would look like a regular server-side script, the difference being that it writes the html out to a file, instead of to an output stream.
 
PHP does the trick

-Job- said:
You can still use anything you want, because you can have a PHP script start your HTML writer app. Of course since you have PHP available i would just use PHP.
Your PHP script would look like a regular server-side script, the difference being that it writes the html out to a file, instead of to an output stream.

I agree w/ this. PHP is the easy way to go. Out of curiousity, what is the hit rate on this system. Accessing a database is so fast that I have php apps to generate the page on the fly. But that's just me.
 
Is there an efficient way of redirecting my PHP to a file rather than back to my browser? I've got all the code to make the page; I hope I don't have to rebuild it all as print statements...

rdx said:
I agree w/ this. PHP is the easy way to go. Out of curiousity, what is the hit rate on this system. Accessing a database is so fast that I have php apps to generate the page on the fly. But that's just me.

Like I said, hit rate or no, my pages take 5-20 seconds to load. Sometimes they time out. Granted, this is because of a shared SQL server, but still, why access the db several hundred times for the same data?
 
DaveC426913 said:
Like I said, hit rate or no, my pages take 5-20 seconds to load. Sometimes they time out. Granted, this is because of a shared SQL server, but still, why access the db several hundred times for the same data?

That sounds like a lot. Are these very large documents? Is the SQL Server on a separate machine?
 
  • #10
Dave, what you could do is the following. Write out your website in PHP as if you meant to leave it as a dynamically generated site. Suppose you have the following structure:
Code:
/root
  file1.php
  file2.php
...and you want to have the html versions as well:
Code:
/root
  file1.php
  file1.htm
  file2.php
  file2.htm

The html version are the ones you'd make publicly accessible.
Converting from php to html, just involves running the PHP and capturing the HTML it outputs. So suppose you do an http request from your local server to your local server for the file "http://localhost/root/file1.php". Then your server will reply with the html, and all you have to do is save it to a file.
You can do http requests with PHP, using fopen:

Code:
$handle = fopen("[PLAIN]http://www.example.com/",[/PLAIN]  "r");

So i would do the following. Do a php script, generator.php, which receives a variable "page". So for example, generator.php?page=file1.php
Inside generator.php you get the value of the page variable:
Code:
$targetPhpPage = $_GET["page"];
$targetHtmPage = str_ireplace(".php", ".htm", $targetPhpPage);
Then you make an http request to the target page:
Code:
$handle = fopen("[PLAIN]http://localhost/root/"[/PLAIN]  . $targetPage, "r");
Then you read the html you get from the server and dump to an html file
Code:
while ($data = fread($handle, 4096)) {
     //dump $data to $targetHtmPage
}

Then it would be a simple matter to add links to your control panel to enable you to generate/update html for a page. Maybe a dropdown list or tree view populated with a list of php files and a button. When you click the button it submits to generator.php?page...
This way if in the future you find that you don't need this process anymore, you won't need to change anything, just make your php pages directly available.

For reference:
http://us3.php.net/fopen
http://us2.php.net/manual/en/function.str-ireplace.php
http://us2.php.net/manual/en/function.fread.php
 
Last edited by a moderator:
  • #11
I will try this. Thanks muchly.
 

Similar threads

  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 6 ·
Replies
6
Views
3K
  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 50 ·
2
Replies
50
Views
9K
  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 5 ·
Replies
5
Views
3K
Replies
7
Views
3K
  • · Replies 15 ·
Replies
15
Views
3K
  • · Replies 5 ·
Replies
5
Views
3K
  • · Replies 23 ·
Replies
23
Views
4K