ucantblamem

Archive for September, 2007

Server status check class

5th Sep 2007

Today I had to make some updates to SM2’s hosting server-status module, which I admittedly built in a rush. The result is that I put a decent effort in this time, even going to the extent of researching HTTP and POP3 protocols to make sure I get the right return messages.

So, I have this funny feeling I’ll never have the necessity to update this, but here is Version 0.1 of the ServerCheck abstract class, which you’re welcome to take and do with it what you like (under the MIT license).

Example usage:

if (ServerCheck::pop('mail.ucantblamem.com')) {
    echo 'Server is online!';
} else {
    echo ServerCheck::error();
}

The class uses fsockopen() to test a server and the timeout is set to 2 seconds by default; if you want to change that, you can do that like so:

ServerCheck::set_timeout(3);

You can also override the default ports (which is 80 for web and 110 for pop) by specifying the second parameter:

if (ServerCheck::web('http://secure.heritageonline.com.au/', 443)) {
    echo 'Server is online!';
} else {
    echo ServerCheck::error();
}

This class is written as an abstract PHP 5 class, but if wouldn’t take too much effort to back-port it as a regular PHP 4 class if need be.

This class is very simple (hence the 0.1), so if you do use this class and add to it feel free to send it back my way; it would be nice to eventually have a really widely usable class compiled, which of course I’ll put on offer here.

Introduction to Objective-c and Cocoa from a web developer’s perspective

2nd Sep 2007

Aren’t you a web developer?

Late last year I read a book called Advanced PHP Programming, which introduced me to the idea of learning other languages (from what I use at work) to gain better understanding of programming best-practices and paradigms.

Earlier in the year I did a big stint of Ruby and Rails which gave me great insight into the power of a truly objective language as well as MVC and ActiveRecord etc… For the last couple of months I’ve been studying Objective-c and the Cocoa API which, as you may or may not know, is the underlying language/framework behind Mac OS X.

So far I am completely blown away by how advanced it all is, I really expected it to be much more low-level and assembler-like, but I can safely say that Cocoa rivals the beauty of Rails and Objective-c is the perfect language to drive it. Unfortunately, to the untrained eye it can seem quite alien and the initial introduction is difficult if you’re coming from the web-based world.

So to help my coding brethren out, here is my little Introduction to Objective-c and Cocoa from a web developer’s perspective: (more…)