Error-free PHP

Not nearly as good as it sounds. I’ve become plagued by a very irritating problem over the last couple of weeks – I’m getting no error output from PHP whatsoever, neither to the browser nor to logs, even though all such options are enabled. My config files are as stock as they can be and still work. It’s just making debugging nearly impossible. I’m getting the same symptoms on OS X and RedHat EL4, so it’s not a platform-dependent thing. They are also on different versions of Apache (2.0.54-12 from Fink and 2.0.52 from RHN). Grrr.

I found it!! Really silly issue and it explains everything. There was a .htaccess file containing an old line:

php_value display_errors true

It appears that (unlike in the rest of PHP) ‘true’ is interpreted as boolean false in this context. Commenting it out or setting it to 1 makes it work.

PHP register_long_arrays session breakage

Strange behaviour that’s taken me ages to track down. I had the situation where I could create a session, but any changes to it were not saved. session_write_close() didn’t help. Eventually I tracked it down: if you have register_long_arrays disabled (as is the default in PHP5), this can happen. Enabling it fixed the problem. A very simple test case didn’t show this problem, so I guess something in my sessions has a dependency on HTTP_GET_VARS or similar, though these vars do not appear anywhere in my code…

Someone pointed me at this bug report which seems very similar to what I’m seeing. Still no solution though.

Beware of the MultiView

I’ve been seeing some very confusing behaviour involving mod_rewrite and PHP.

I have this rewrite rule in a .htaccess file (it just allows me to see what the incoming URL looked like for test purposes):

RewriteRule (*.) x.php?x=$1 [R,L]

If I feed it a URL like:

it matches the whole thing/123 part and maps it to my desired URL:

That’s all fine. Now the weird bit. If I happen to have a script with the same base name as the matching path part, like “thing.php”, it gets magically picked up and inserted into the URL, so I end up with:

Huh?! How did the ‘.php’ get in there?

Now because this rule is in a .htaccess file, it’s handled last in the chain of things that apache might do (and there are no other rewrite rules), it must be something further upstream that’s mapping ‘thing’ to ‘thing.php’. My first idea was that it might be looking inside thing.php (using mime_magic) and mapping its type, and file extension, according to the AddType directive that PHP is enabled by. However, turning off mime magic doesn’t stop it happening, so it’s not that.

It DOES stop doing it if I disable PHP – but why should PHP be involved in this at all? The final URL will eventually hit PHP, but because in this case I’m using [R] (which forces an external redirect) in the rewrite rule, PHP won’t see that until the request returns from the browser.

Is there some automatic aliasing thing that suggests that files without extensions might be some other kind of file? Well, that sounds like a fair description of the kind of thing that Apache’s MultiViews do. Surprise surprise – I turn MultiViews off and it all starts acting normally. As yet I’ve not figured out how to stop it a little more selectively (as MultiViews are a nice feature otherwise), but I can live without them for now.

PowerBook 5300 batteries

I recently flogged a couple of Apple PowerBook 5300ces on eBay. Their only problem was that the batteries were dead. A replacement costs around £90, about 3x the value of the entire laptop… I had a spare battery, so I took it apart (it’s all glued, so needs a bit of force). inside are 12 NiMH solder-tagged cells all a little larger than standard AAs, a thermal cutout wired inline, and a little 2-wire serial number chip attached to a couple of the extra contacts on the casing. The battery is rated at 1900mAH, which considering the size of the cells is not great. I checked for sizing, and you can easily get two 6-AA battery holders in. Wiring up the thermal trip is easy enough, and you can leave the serial chip in place. This could get you 2500mAH (with current top-end AAs) at a fraction of the cost of a replacement while also saving quite a bit of weight. I didn’t actually do it as was selling the laptops in their battery-less state, but it was an interesting exercise nonetheless.