About Growl...

Growl icon

As described on the Growl website, Growl is a global notification system for Mac OS X. Any application can send a notification to Growl, which will display an attractive message on your screen. Growl currently works with a growing number of applications.

In order to test Net_Growl with PHP, you will need Growl version 0.7. Net_Growl has been tested with Growl 0.7.2. Find the installation instructions there.

When setting up Growl in the System Preferences, make sure the Growl Network tab allows remote application registration and incoming notifications through the network.

Projets

PEAR::Net_Growl

PEAR::Net_Growl relies on version 0.7 of Growl which supports remote connections using the UDP protocol. PEAR::Net_Growl allows PHP applications to notify Growl and have the notification displayed directly on the desktop.

There can be lots of uses for such a tool :

  • Display warnings, notices, messages outside of the browser.
  • Display PEAR_Error, exception messages as they happen.
  • Display remote services status.
  • Display debug information, without interfering with http headers.
  • Display cookie contents, etc.

Basic example

Below is a basic example. You can use this code to check that everything is working fine:


<?php
require_once 'Net/Growl.php';

$growl =& Net_Growl::singleton('Net_Growl', array('Messages'));
$growl->notify('Messages', 'Hello', 'How are you ?');
?>

Growling PEAR Errors

PEAR_Error with Growl

Using a callback, it is easy to display PEAR_Error messages with Growl.

 

The above example can be done using the following code and Net_Growl:


<?php
require_once 'Net/Growl.php';

function growlErrors($error)
{
  $growl =& Net_Growl::singleton('Net_Growl', array('PEAR_Error'));

  $growl->notify('PEAR_Error', 
                 get_class($error),
                 $error->message.' in '.$_SERVER['SCRIPT_NAME'],
                 array('sticky' => true));
}

PEAR::setErrorHandling(PEAR_ERROR_CALLBACK, 'growlErrors');
?>

Together with Event_Dispatcher

Event_Dispatcher is a PEAR package which is used to notify PHP objects of interesting things. Net_Growl can easily be used to listen to all notifications sent to Event_Dispatcher and inform you about what is happening in your code.


<?php
require_once 'Net/Growl.php';

function notifyInGrowl(&$notification)
{
  $growl =& Net_Growl::singleton('Net_Growl', array('Notification'));

  $infos = $notification->getNotificationInfo();
  $title = $notification->getNotificationName());

  $growl->notify('Notification', $title, $infos['message']);
}

if (class_exists('Event_Dispatcher', false)) {
  $defaultCenter =& Event_Dispatcher::getInstance();
  $defaultCenter->addObserver('notifyInGrowl');
}
?>

Where is the source ?

You can find the package code using the following links:

How to install ?

You can install Net_Growl on your Mac using the following command from the Terminal:


$ pear install -f Net_Growl