SiteCrafting Blah Blah Blog
Mar. 26, 2008 at 12:41pm
Make PHP Growl
. . . but in a good way!

I stumbled upon a fantastic PHP class today and felt compelled to comment on it. Originally written by Tyler Hall, this class allows you to send notifications to any system running Growl from a PHP script. For those of you that don't know, Growl is an application written for Mac OS X that is intended to act as a universal notification tool (much like the taskbar notification bubbles we've all come to know and love in Windows XP/Vista).
The class itself is incredibly simple and straightforward, and allows you to send notifications using only 5 lines of code. Consider this simple example:
// Setup
$growl = new Growl();
$growl->setAddress('127.0.0.1');
$growl->addNotification("Test");
$growl->register();
// Send Notification
$growl->notify("Test", "Test Alert", "The body of the test alert!");Pretty nifty isn't it? One could very easily integrate this into a logger to notify you immediately of any critical errors with your scripts, or even tell you every time a given page is viewed. So if you want to check out my modified version (a bit more standards-compliant with PHP 5) you can see it here, or view the original author's site to see the original.
Download: Growl PHP Class
Posted in PHP, Review, Software Engineering by Nick Williams
Comments (8)
I assume that the address of 127.0.0.1 could be set to any ip/address? This could be amazingly handy when it comes to debugging ajax scripts and things which have no real output.
I could imagine some fun uses for this! I bet that could integrate well with the new jabber ajax client (link below). http://sourceforge.net/project/screenshots.php?group_id=220605
1 | Left by Paul | Mar. 26, 2008 at 1:49pm
Nick says:
Absolutely - I should have mentioned that as well. You can specify virtually any type of valid network address (IP addresses, domains, and if you're on a local network computer names can be used as well). I imagine there are things I haven't even thought of that this could be used for - it should be fun to play with.
2 | Mar. 26, 2008 at 3:04pm
Hey, Nick. Thanks for the great write-up. Definitely let me know if you run into any issues with the code.
3 | Left by Tyler | Mar. 26, 2008 at 3:41pm
Nick says:
Thanks Tyler - as simple as it is, you've created something incredibly useful. Congrats and thanks for sharing!
4 | Mar. 26, 2008 at 4:00pm
Thanks, didn't know about this one!
@Paul: Take a look at the firebug addon for firefox! Saved my life.
5 | Left by kvz | Mar. 27, 2008 at 12:32am
Just for those that might not be able to see this working, in your Growl preferences you need to enable it to listen for incoming connections on the network and allow remote application registration (this wasn't set as default for my install)
6 | Left by Scrivna | Mar. 27, 2008 at 2:31am
Ahh very cool! Never heard of it, thanks!
7 | Left by Menekali | Mar. 27, 2008 at 1:31pm
Im already drewling, this one will be so fun
8 | Left by mijako | Apr. 4, 2008 at 2:29am