OrbWars 6 Coming Soon
Update This page previously contained a statement regarding the closure of OrbWars down over a year ago - BUT OrbWars will be returning soon, check the website over at http://www.orbwars.co.uk for more details once I get it all finished!
Simple caching in PHP5
I’ve just written a script that reads from a few webpages and I faced a problem of the servers sometime being slow and delaying my page display, so I decided to write a simple caching object:
class cache {
function __construct($path='.') {
$this->path = $path;
}
function cache($name, $callback, $args) {
if (file_exists("$this->path/$name")) {
$this->callbacks[$name] = array($callback, $args);
return implode('', file("$this->path/$name"));
} else {
return $this->save($name, $callback, $args);
}
}
function save($name, $callback, $args) {
$text = call_user_func($callback, $args);
$fh = fopen("$this->path/$name", 'w');
fwrite($fh, $text);
fclose($fh);
return $text;
}
function __desctruct() {
if (is_array($this->callbacks)) {
foreach ($this->callbacks as $name => $callback) {
list($callback, $args) = $callback;
return $this->save($name, $callback, $args);
}
}
}
}
You call it using:
$cache = new Cache();
$cache->cache('MyFunc.txt', 'MyFunc', 'an argument');
All it does is save the output of the function to a file with the given name. The clever bit is that the output it sends to the browser is the content of the file; it doesn’t actually call the function until the end of the script execution and so doesn’t slow the output to the browser down.
- Start sending output.
- Output cached result of function.
- Finish sending output.
- Call function and save to the cache file.
It means the content will always be slightly out of date, but in a lot of situations that may not be a problem. Quick note, this is only really possible (at least the way I’ve done it) in PHP5 because it requires destructor support.
Why people think Finnish is a hard language
This page lists the 2253 forms of the word “kauppa”, Finnish for “shop”. Finnish is highly agglutinative so having a lot of forms for each word is expected . But this is rather more than most people would predict I think. It isn’t as bad as you think since Finnish suffixes embody concepts most languages use several words for. i.e. Finnish uses longer words in most sentences but there are fewer of them.
This is cleverly embodied in the quote from this site: “Why lose time and energy saying ’the committee that takes care of negotiations concerning the truce’ when you can use a simple little word like ‘aseleponeuvottelutoimikunta?’”
Beam me up Scotty
Well it seems a bit late since it’s everywhere else, but I thought I should at least mention the recent death of James “Scotty” Doohan. For more information visit CNN.
Google Moon
Google have put a load of satellite images of the moon along with data of various moon landings to provide us with Google Moon.
Plugins
I’ve apparently installed two pugins for Wordpress. One is simpletags allowing me to add Technorati tags to posts easily, and the other is bstat, a nice stats plugin. So we’ll see if they work.
New OrbWars/Galaxia Forums
The Galaxia and OrbWars forums have merged. Not terribly apparent since there haven’t been any Galaxia forums for a long time and as such it only has one actual forum. But still, check it out: http://forums.orbwars.co.uk.
IC to host IVDC
Imperial College’s bid to host the Inter Varsity Dancesport Competition in 2006 has been succesful and I’m on the “support team”.
Wohoo!
Public development version of Galaxia Reborn
The current version of Galaxia Reborn is now available to play with. You can’t actually do that much but some things are still fun to play with.
Signup works but doesn’t actually give you anything you can use so just login as “Q” with password “q”.
You can move ships around and build more at the colony (you have to find the colony first though :P) although you can’t send them into space just yet. Also, the entire interface has been translated into Finnish (well almost. Two little bits were added afterwards but they’ll get done soon enough). Thanks for that go to my girlfriend Julia. If anyone is interested in translating the interface into a different language let me know . You’ll get a permanent link on the info panel at the bottom for people using your language as well as a mention in any credits.