[thelist] Static Page Generation with PHP

Sam sam at sam-i-am.com
Wed Sep 3 10:12:12 CDT 2003


I'm working on something similar right now, in Perl.
My problem differs in that I'm building packages that comprise one or 
more web pages and all their dependees, as well as any other relevant 
assets like PSD comps, IA diagrams, readmes, or whatever.
Here's my approach:

I parse the html (which I wrote, so I can do so fairly reliably) for all 
the dependancy relationships. I create a dependancies.txt file that has 
filenames for all the images, html, css, etc that are necessary for the 
pages to render.
I also keep an additional text file for filenames for the other assets - 
and anything my parser might consistently miss - like assets implied by 
javascript (which I'm not parsing).

I have a very generic zipmaker (also perl - but I think pkzip has a 
facility like this) that accepts filelists, and outputs a zip file to 
the directory of my choice. This can be invoked as a cgi (responding 
with a zip mime-type) or offline to just statically build the zip.

So, I try and break the pieces of the task off into specialized 
processes. The parser, the aggregation of zip contents (which can be a 
manual process), and the zip creation itself.

I'm refactoring the parser right now, but otherwise the pieces are in 
place. Any day now scores of zip files will turn up, and I'll have a 
tool to update them at will. Noone need be the wiser that I didn't build 
each by hand.

hope this helps a little - I know it's not directly applicable, but my 
lessons learnt might apply: Keep it simple, and allow for manaul 
intervention at each step. If something breaks or a requirement changes, 
you can still use those parts of the system that function.


> Ideally, I would like to write all the HTML into a variable or array
> and then store the files in a ZIP somehow that the user could
> download. I just can't quite seem to get my heard around how to go
> about it.

I'd suggest you write the html to a tmp directory, zip it, remove the 
tmp directory. You can write straight to the zip archive from a 
variable, but as I say above, my gut is to give yourself an opportunity 
to check the output before building the zip.

Sam



More information about the thelist mailing list