PHP and make

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View
What I want to do is to use PHP CLI to generate static pages.  I did this
years ago using gmake (GNU make) to call the php scripts.  However, I really
wasn't very good at it and did not know how to really manage dependencies,
with the result that for the most minor change involving just a few pages, I
was regenerating everything, which was really only a slight improvement on
writing pages manually.  I'm still pretty shaky on gmake (the make based on
pmake that is native to my system), mostly because all the tutorials I can
find begin with the assumption that you want make to compile programs ---
not an unreasonable assumption since that is what make was made for, but
also not very helpful for my purposes, what with the various C-oriented
examples and implicit rules.

I can see that I have basically two kinds of dependencies.

One is the ordinary kind:  a target page depends on an included navigational
menu.  Obviously when the menu changes (when the menu file to be included is
younger) the target page needs to be remade.

The other kind has to do with what I call for want of a better term wikisms.
These are little embedded tags in the content source which point to photos,
or glosses or links or various other objects.  I don't want them to do
anything if what they point at doesn't exist.  But if they exist and are
younger than the target page, I want them to be expanded according to the
properties of whatever they are.

Here's an example:

"Raw" source:

<p>I liked to go to the park with my dog.</p><?php
include(right_image('cute_dog_photo')); ?>

I want to write this without knowing whether I will be able to find a
cute_dog_image.  I want right_image to return nothing if cute_dog_image
doesn't exist in my database and to generate an IMG tag in a right-floated
DIV and upload cute_dog_image to the server, if cute_dog_image does exist.

There is not problem with this so far.  right_image() is written and works
and so forth (and actually does a lot more such as wrapping the image in a
link to a larger version if one is known and adding a caption).  But
cute_dog_image is a new kind of dependency -- if it is younger than the
target page, the target page should be rebuilt (just like when the menu was
younger).  But if it doesn't exist, then it should be ignored (whereas if
the menu doesn't exist, it should be built if we know how or it should cause
things to come to a screetching halt if we don't know how to build it).

So my question is, is there something in PHP to make handling this sort of
stuff easy so I don't have to use a make flavor (and don't have to write a
bunch of stuff myself using fstat and so forth.

        Lars Eighner <
 To parse a query string in CLI use parse_str() or build a function based
on the example in the manual page for urldecode().  For URIs scraped from web
                     pages, change any &amp; to & first.

Re: PHP and make

Quoted text here. Click to load it

I don't think you can sensibly do this if non-html content is accessed
using a php script - up until you mentioned the problem with the
image, I was going to suggest configuring your webserver to apply PHP
parsing to .html files, name all your PHP files as .html then either
using a spidering program to dump the entire site or create a wrapper
script around any files you deploy into live. The problem is that if
you are generating different mime-types from your php code then you
need to change both the output filename and the refering code, while
minimising any duplication.

OTOH, if the non-html content already exists as files outside of the
database, and the thing which changes is the snippet of html code
around the url of the image, then all you need to do is run with 3
versions of the website - the original PHP(1), a dump of the current
PHP site(2) and the 'published' non-php version(3). Then you just need
to dump the whole website (1->2) and compare the dump with the
published version (2->3) to identify files which are different (e.g.
using rsync).

This approach would also identify any updates which occur to the data
(e.g. image urls added, database updates).

The other way to solve the problem would be to get the PHP to generate
your own markup language using sepcific tags for tags such as include
(right_image('...')) and re-parse the expression at publish-time
(although this is, in effect) little different from then previous


Site Timeline