Redesigning my blog, for reals this time

Okay, so this is about the 4th theme I’ve picked for my blog, though I doubt anyone reads it anyway. In any case, this time I finally realized that I’ll never be happy with the coding style of another WordPress theme developer, so I started from scratch. Plus, I really wanted to try using 960.gs, and converting an existing theme from one framework (or no framework) to another is pretty hard and time-consuming. So here’s my brand new theme, with not many features or anything. Hope you like it. =)

PHP daemontools service with SIGHUP support

Here’s a template script for writing a daemontools service in PHP. It handles HUP signals, so you can make the service reload its configuration file without restarting.

<?php
 
// Don't forget this line or signal handling won't work:
declare(ticks = 1);
 
// This global flag is used to trigger a configuration file reload.
$load_config = true;
 
// The SIGHUP handler doesn't do any actual work; it just sets the flag.
function handle_hup($signal) {
global $load_config;
$load_config = true;
pcntl_signal(SIGHUP, 'handle_hup', false);
}
 
// Register the signal handler.
pcntl_signal(SIGHUP, 'handle_hup', false);
 
// Start the service.
echo "myserver: starting service\n";
while (true) {
// Load the config file if necessary.
if ($load_config) {
$load_config = false;
echo "myserver: loading configuration\n";
include 'config.php';
}
 
// Do something useful.
// ...
 
// Pause for a configurable amount of time.
echo "myserver: sleeping for $SLEEP_TIME seconds...\n";
sleep($SLEEP_TIME);
}
 
?>

And in config.php, you can start with something like this, to make the sleep time configurable:

<?php
 
// Sleep time in seconds.
 
$SLEEP_TIME = 60;
 
?>