00001: <?php
00002: /**
00003: * Example that send notifications to Growl using the new GNTP/1.0 protocol
00004: *
00005: * PHP version 5
00006: *
00007: * @category Networking
00008: * @package Net_Growl
00009: * @author Laurent Laville <pear@laurent-laville.org>
00010: * @author Bertrand Mansion <bmansion@mamasam.com>
00011: * @license http://www.opensource.org/licenses/bsd-license.php BSD
00012: * @version CVS: Release: @package_version@
00013: * @link http://growl.laurent-laville.org/
00014: * @since File available since Release 0.9.0
00015: */
00016:
00017: require_once 'Net/Growl.php';
00018:
00019: // Notification Type definitions
00020: define('GROWL_NOTIFY_STATUS', 'GROWL_NOTIFY_STATUS');
00021: define('GROWL_NOTIFY_PHPERROR', 'GROWL_NOTIFY_PHPERROR');
00022:
00023: // define a PHP application that sends notifications to Growl
00024:
00025: $appName = 'PHP App Example using GNTP';
00026: $notifications = array(
00027: GROWL_NOTIFY_STATUS => array(
00028: 'display' => 'Status',
00029: ),
00030:
00031: GROWL_NOTIFY_PHPERROR => array(
00032: 'icon' => 'http://www.laurent-laville.org/growl/images/firephp.png',
00033: 'display' => 'Error-Log'
00034: )
00035: );
00036:
00037: $password = 'mamasam';
00038: $options = array(
00039: 'host' => '192.168.1.2',
00040: 'protocol' => 'tcp', 'port' => Net_Growl::GNTP_PORT, 'timeout' => 15,
00041: 'AppIcon' => 'http://www.laurent-laville.org/growl/images/Help.png',
00042: 'debug' => dirname(__FILE__) . DIRECTORY_SEPARATOR . 'netgrowl.log'
00043: );
00044:
00045: try {
00046: $growl = Net_Growl::singleton($appName, $notifications, $password, $options);
00047: $growl->register();
00048:
00049: $name = GROWL_NOTIFY_STATUS;
00050: $title = 'Congratulation';
00051: $description = 'Congratulation! You are successfull install PHP/NetGrowl.';
00052: $options = array();
00053: $growl->notify($name, $title, $description, $options);
00054:
00055: $name = GROWL_NOTIFY_PHPERROR;
00056: $title = 'PHP Error';
00057: $description = 'You have a new PHP error in your script P at line N';
00058: $options = array(
00059: 'priority' => Net_Growl::PRIORITY_HIGH,
00060: );
00061: $growl->notify($name, $title, $description, $options);
00062:
00063: $name = GROWL_NOTIFY_STATUS;
00064: $title = 'Welcome';
00065: $description = "Welcome in PHP/GNTP world ! \n"
00066: . "New GNTP protocol add icon support.";
00067: $options = array(
00068: 'icon' => 'http://www.laurent-laville.org/growl/images/unknown.png',
00069: 'sticky' => false,
00070: );
00071: $growl->notify($name, $title, $description, $options);
00072:
00073: var_export($growl);
00074:
00075: } catch (Net_Growl_Exception $e) {
00076: echo 'Caught Growl exception: ' . $e->getMessage() . PHP_EOL;
00077: }
00078: ?>