« Creating a Photo Album | Main | What does "Syndicate this site" mean? »

HTML or PHP?

This article is out of date and doesn't touch on MT's dynamic publishing features. ~Elise February 22, 2007

When you are first setting up a new weblog, Movable Type prompts you to choose a file extension in the weblog config preferences section. The default setting is HTML.

file_extension.gif

If your server allows PHP scripts, and you would like to add customization features that aren't part of the default Movable Type system, it is highly recommended that you choose PHP as your default file extension preference in place of HTML. Doing so allows you to take advantage of many freely available PHP scripts to help customize your weblog. PHP is an open source scripting language that is powerful, stable, and extremely popular for adding dynamic elements to websites. In your Movable Type weblog, PHP scripts can allow you to do random photos, includes, and skinning, among many other things. PHP can also help you create a more modular approach to building your templates, thus reducing rebuild times.

To give your entire weblog php extensions, write php in place of html where prompted in the weblog config preferences section. In the weblog config archiving section change the archive file template extensions from html to php. On your index templates, change the extensions of your output files to php. (See the Converting to PHP Tutorial to convert your site to PHP.) If you only want to invoke a PHP script on the Main Index and not on any other pages (for example to generate a random photo on your main page), just change the output file of the template from index.html to index.php. (If you do this, make sure to delete the index.html file from your server (using an FTP program). Left of the server, the index.html file will served instead of the index.php file.)

Cool things to do with PHP:
PHP Skinning Tutorial - Domesticat.net
Random Image Rotation - PHP script from A List Apart
Relative Dates PHP script - change from "Posted Aug 1" to "Posted 3 days ago".

Links:
Converting to PHP - LMT Tutorial
An Introduction to PHP by John Coggeshall

Comments (2)

Good article! However... :)

It is true that using PHP allows great flexibility in building dynamic scripts. However, for people (or blogs) that do not really need this, HTML is *much* preferable, since it generates static pages. The points?

1. Caching. Since the pages never change (unless you rebuild them, of course), your browser, your HTTP proxy *and* your webserver can all cache them instead of transferring them, thus saving time and network traffic.

2. Server load. If your webserver is asked to serve a file with a 'php' or 'php3' extension, it passes the file to its PHP interpreter. Even if the interpreter is a build as a module, this still adds some overhead to the processing - and if you have no PHP code within the page, this is absolutely unneeded overhead that can slow down your server a lot.

So basically.. the recommendation to use 'php' as the file extension should only be given for blogs that *will really use it* - for the rest, it *will* result in more network traffic and more server processing.

Peter - thanks for the clarification! I've been searching the MT forums for the "downside" and hadn't found any. I've been using php on several of my blogs now for many months without a problem. In fact, it greatly speeds up the rebuilding process. But if you weren't planning to do any customization that might require PHP then it's unneccessary.