CakePHP's invisible query cache
Wednesday, May 23. 2007
I just wanted to document something that was driving me nuts in Cake PHP.
I do a simple find on a model:
$thing = $this->Model->find(array('id' => 123), NULL, NULL, 1);
Then later on, I make the same query again. Only the first query appears in the SQL debug output. Why call it again? Well, I've made some manual queries in between the calls using SQL that is inconvenient to emulate in Cake functions, in particular INSERT IGNORE. It turns out that Cake has a largely undocumented query cache, but Cake has no idea that its cache is dirty because of the manual queries. The _clearCache function is not yet implemented for the query cache, so the only choice is to disable it before the first query, and you can do that during a single instantiation by saying:
$this->Model->cacheQueries = false;
Note that the query has 1 level of recursion, which means that all the sub-queries are also cached. Setting cacheQueries to false on this one model means that all queries through it don't get cached, including those that may be in other models via relationships.
Who's the Daddy?
Saturday, May 19. 2007
3Ware RAID rebuilding
Monday, May 14. 2007
I've had the dubious honour of seeing some RAID failures and rebuilds lately. It's the kind of thing that doesn't get written about in the manuals very well, in particular what your RAID will report when it's having trouble. So, here are a couple of examples from a 3Ware RAID controller using tw_cli software. This is what tw_cli /c4 show displays when we have a dead drive:
Unit UnitType Status %RCmpl %V/I/M Stripe Size(GB) Cache AVrfy ------------------------------------------------------------------------------ u0 RAID-1 DEGRADED - - - 149.05 ON - Port Status Unit Size Blocks Serial --------------------------------------------------------------- p0 OK u0 149.05 GB 312581808 G2109NHG p1 DEGRADED u0 149.05 GB 312581808 G20X1BWGSo, we swap the drive, and it looks like this while rebuilding:
Unit UnitType Status %RCmpl %V/I/M Stripe Size(GB) Cache AVrfy ------------------------------------------------------------------------------ u0 RAID-1 REBUILDING 89 - - 149.05 ON - Port Status Unit Size Blocks Serial --------------------------------------------------------------- p0 OK u0 149.05 GB 312581808 G2109NHG p1 DEGRADED u0 149.05 GB 312581808 G209Y0HGand after a little while...
Unit UnitType Status %RCmpl %V/I/M Stripe Size(GB) Cache AVrfy ------------------------------------------------------------------------------ u0 RAID-1 OK - - - 149.05 ON - Port Status Unit Size Blocks Serial --------------------------------------------------------------- p0 OK u0 149.05 GB 312581808 G2109NHG p1 OK u0 149.05 GB 312581808 G209Y0HGThere are plenty of obvious strings to match in this output (though there are many other reports available), so it's a reasonable thing to base a monitoring script on. It's nice to see it actually work, and makes me extremely grateful that I bothered getting RAID n the first place. This would be a much unhappier post if I hadn't.
CakePHP hasManyAndBelongsTo relationship limitations
Monday, May 14. 2007
Cake has some nice support for modeling many to many relations using 'hasManyAndBelongsTo'. There's a simple example here.
Though this works well for simple connections between classes, you can't do much else. Taking the classic Blog-style Posts and Tags example, this approach will easily let you link multiple tags to multiple posts. But what if you want to track the date that a tag was applied to a post? If you add a date field to the join table, it seems pretty much impossible to retrieve it, and setting it is even harder. You can search on it by twiddling with the conditions on the relation, but that's ugly. I think in that case, you have no option but to model the relation explicitly with two pairs of hasMany/belongsTo relations linked through a PostTag model, and then you'll have to set your recursion deeper and get busy with unbindmodel in order to keep the number of queries down. Who knows, I might even write up an example and post it here...
PHP London Take 4
Saturday, May 12. 2007
A simplified London shape (Based on Sadiq's) with an exaggerated river:

It'd difficult to place the text without interference with the river, so I thought I'd try it offset.

It'd difficult to place the text without interference with the river, so I thought I'd try it offset.
PHP London Take 3
Thursday, May 10. 2007
Trying a few with the river in the middle, and a different rectangular arrangement.

The outlines are a little thin at this resolution.

The outlines are a little thin at this resolution.
PHP London Logo Take 2
Thursday, May 10. 2007
I've done a bit of work on the logo so it's actually a logo and not just a bit of text! I kept the river theme. Here are a few colour variations (mostly using "official PHP Blue"), and minor spacing variation on "London". What do you think?
PHP London Logo
Wednesday, May 9. 2007
Here's my attempt at a PHP London logo. It's just a bare logotype, but might form a basis for more elaborate designs:
It's derived from the official PHP logo which is provided as a vector outline. I couldn't find or identify the typeface - it looks a bit like Eurostile or ProFont (but it isn't either) - so I redrew the characters to match.
Obviously there is scope for all kinds of arrangements (and not outlining), but at least we now have a "London" in a typeface that exactly matches the logo.
For those that like to twiddle, here is the Illustrator CS2 file (should be PDF compatible, probably need to right click to download it as it has a dumb mime type). The file also includes an uncombined version. Creative Commons License.
It's derived from the official PHP logo which is provided as a vector outline. I couldn't find or identify the typeface - it looks a bit like Eurostile or ProFont (but it isn't either) - so I redrew the characters to match.
Obviously there is scope for all kinds of arrangements (and not outlining), but at least we now have a "London" in a typeface that exactly matches the logo.
For those that like to twiddle, here is the Illustrator CS2 file (should be PDF compatible, probably need to right click to download it as it has a dumb mime type). The file also includes an uncombined version. Creative Commons License.


