WP SuperCache .htaccess mod_rewrite rules for Blogs in Subdomains/Subdirectories
I have a unique problem, which is that I have installed my wordpress to a subdirectory, and symlinked httpdocs from several subdomains to that directory. The structure looks like this:
httpdocs/wp/ -> WP Install
subdomains/gadgets/httpdocs/ -> /elliottback.com/httpdocs/wp/
subdomains/books/httpdocs/ -> /elliottback.com/httpdocs/wp/
This means that from my domain, we’re always sticking an extra /wp onto things, but from the subdomains, they go directly into the wp-content directories from the root , in both relative and absolute sense. I consolidated my subdomains this way so that I could run a single WP install and maintain them together. Here’s the .htaccess file that lets WP Super Cache work on either of them:
# BEGIN WPSuperCache
<ifmodule mod_rewrite.c>
RewriteEngine On
AddDefaultCharset UTF-8
RewriteBase /
RewriteCond %{REQUEST_URI} !^.*[^/]$
RewriteCond %{REQUEST_URI} !^.*//.*$
RewriteCond %{REQUEST_METHOD} !=POST
RewriteCond %{QUERY_STRING} !.*=.*
RewriteCond %{HTTP:Cookie} !^.*(comment_author_|wordpress|wp-postpass_).*$
RewriteCond %{HTTP:Accept-Encoding} gzip
RewriteCond %{REQUEST_URI} ^(/wp)?/
RewriteCond %{DOCUMENT_ROOT}%1/wp-content/cache/supercache/%{HTTP_HOST}/%1/$1/index.html.gz -f
RewriteRule ^(.*) %1/wp-content/cache/supercache/%{HTTP_HOST}/%1/$1/index.html.gz [L]
RewriteCond %{REQUEST_URI} !^.*[^/]$
RewriteCond %{REQUEST_URI} !^.*//.*$
RewriteCond %{REQUEST_METHOD} !=POST
RewriteCond %{QUERY_STRING} !.*=.*
RewriteCond %{HTTP:Cookie} !^.*(comment_author_|wordpress|wp-postpass_).*$
RewriteCond %{REQUEST_URI} ^(/wp)?/
RewriteCond %{DOCUMENT_ROOT}%1/wp-content/cache/supercache/%{HTTP_HOST}%1/$1/index.html -f
RewriteRule ^(.*) %1/wp-content/cache/supercache/%{HTTP_HOST}%1/$1/index.html [L]
</ifmodule>
# END WPSuperCache
Let me know what you think–performance stats show that it’s working fine for both the /wp subdirectory and the other subdomains!
Staten Island Film Festival 2009
I went to the Staten Island Film Festival today to watch Block Three: Love Is Hard To Find (1 hr 28 min). I saw the following films:
Love Bombing (7 minutes)
Director: Philip Lepherd

Four friends discuss the cult recruitment technique of ‘Love Bombing’. Three of them seem to know an awful lot about it. Is it possible they’ve tried the technique before?
I thought this film was absolutely a blast, from the brilliantly sharp production quality and cinemetography, to the lovely accents and crisp dialog. It’s a great short film on the concept of Love Bombing, a process cults use to attract new blood. Check out the trailer on IMDB, too, it’ll give you some sense of it.
Number Nine (26 minutes)
Director: Brendan Ferrer

Set in an underwear factory called Material World Garments, Number Nine tells the story of Inspector #9, a meek briefs inspector who is color-blind. This could be the worst day of #9’s life, until he meets Miss #9, his equivalent in the brassier department.
An excellent short film, Brendan’s choice to shoot in black-and-white perfectly matches the total colour-blindness of the protagonist. The 35mm gives the film and old-style Three-Stooges feel (although Brendan said he was shooting for Chaplain). At 26 minutes, it’s probably 6 minutes too long, but it rarely drags.
Avatars (30 minutes)
Director: Michael Ofenheim
When Lisa catches her husband, Tyler, cheating on her in cyberspace, HotWetLinda turns the tables on TyMeUp. And, when their avatars meet on a blind date, Lisa discovers that in real-life, two online wrongs CAN make a right.
Although you can buy this movie on Amazon, I don’t recommend watching it. From the start it drags–the cheating husband is so terrible an actor that you feel neither annoyed at him for being a bastard nor sorry for him for losing his love, but total apathy. The mercilessly repeated punchline “So, do you have any Pot?” is Avatars only attempt at humour. The plot itself is tripe, trying to weave together notions of solipsism and internet dating, with a touch of the implausible Nigerian 419 email scam. I don’t know if the director’s brains were addled with pot himself when he did this–but it’s no good at all.
2095 (25 minutes)
Director: Troy Romeo

A young man who falls in love with a woman he thinks is his female co-worker, discovers that his own computer may offer him more than any human ever could.
There’s an interview here. As for the film, it was OK. I felt that too much time and effort ($40,000 and 4 years, according to the director) were spent on the production, leaving the screenplay a bit spaghetti. Its major flaw is that it spends most of the time focusing on the things that don’t matter, and then blitzes by the important developments in seconds.
PHP Exclusive Single Process Mutex
When running php via cron, there are certainly situations where you only want a single instance of the php file to be running at the same time. Multiple processes shouldn’t be allowed. For example, every 5 minutes, a process is launched to poll for weather updates, and publish them to Twitter. If, for some reason, this process takes more than 15m–because Twitter is very slow–I don’t want more to buildup. At a rate of 12/hr, I would exhaust the number of MySQL connection on my box in a couple hours.
So, here’s the solution I used:
<?php
class pid {
protected $filename;
protected $fp;
public $already_running = false;
function __construct() {
$this->filename = dirname(__FILE__).'/'.basename($_SERVER['PHP_SELF']) . '.pid';
$this->fp = fopen( $this->filename, 'w+ );
if ( !flock( $this->fp, LOCK_EX + LOCK_NB ) )
{
echo "FAILED lock $this->filename\n";
$this->already_running = true;
fclose($this->fp);
} else {
echo "Acquired lock $this->filename\n";
}
}
public function __destruct() {
if( !$this->already_running )
{
echo "Releasing lock $this->filename\n";
flock($this->fp, LOCK_UN);
fclose($this->fp);
}
}
}
?>
It works fine from command line, but for some reason, doesn’t work when invoked via Apache over the web. But since I’m just using it for cron jobs, this is good enough for now. If you know why FLOCK( LOCK_EX + LOCK_NB ) won’t work when invoked through Apache, let me know!! I’m running PHP 5.2.6 (cli) and Apache/2.2.9 (Unix).