Make PHP Growl

March 26th, 2008 by nick

GrowlI 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

2 Responses

  1. John Rockefeller

    This is really neat. How does it handle security or authentication, though? A firewall? What’s to stop people from spamming your notification daemon?

  2. nick

    Growl itself actually provides password authentication for notifications received over the network. I’m not sure how secure it is though, but it should have things covered for most cases.

    One thing that would be nice on the Growl side is if it would allow for things like custom icons. Then if you had more than one web app sending them you could more easily differentiate between their notifications.

Leave a Comment

Please note: Comment moderation is enabled and may delay your comment. There is no need to resubmit your comment.