SiteCrafting, Inc.
Make PHP Growl
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
by Nick Williams | 3/26/2008 12:41pm | Comments (32)
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
Left by Paul | Mar 26, 2008
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.
Left by Nick Williams | Mar 26, 2008
Hey, Nick. Thanks for the great write-up. Definitely let me know if you run into any issues with the code.
Left by Tyler | Mar 26, 2008
Thanks Tyler - as simple as it is, you've created something incredibly useful. Congrats and thanks for sharing!
Left by Nick Williams | Mar 26, 2008
Thanks, didn't know about this one!
@Paul: Take a look at the firebug addon for firefox! Saved my life.
Left by kvz | Mar 27, 2008
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)
Left by Scrivna | Mar 27, 2008
Ahh very cool! Never heard of it, thanks!
Left by Menekali | Mar 27, 2008
Im already drewling, this one will be so fun
Left by mijako | Apr 4, 2008
I must admit I would never have thought of this idea! Can't wait to give it a go.. Great stuff
Left by Colin Miller - Freelance web designer | May 29, 2008
I'd really like to give your PHP5 code a shot, but the download link appears to be broken!
Left by Aaron | Sep 4, 2008
Thanks for the heads up Aaron, looks like it was a casualty from our latest site update. The link should be working now.
Left by Nick Williams | Sep 17, 2008
We've been trying to send Growl notifications from our own machines back to our own machines using 127.0.0.1, localhost, local IPs and external IPs but none of them have worked. We eventually tried sending a notification across the internet between two different machines and it worked. Anyone else had this problem? BTW - The PHP 5 link doesn't work.
Left by Alistair Holt | Oct 26, 2008
This is totally awesome. I love it. Just thinking of useful things I will use it for.
Left by kinoli | Dec 30, 2008
Thanks a bunch!
I hope it is cool with you for me to integrate this into my Asteristickies application ( http://geekhut.org/asterisk-stickies/ )
There have been a lot of requests on IRC as well as many forums for easy Growl notifications for asterisk. This script makes my life VERY easy.
Much appreciated!
Left by aster1sk | Apr 1, 2009
hi Nick
Great script!!! thx alot.
I'm using this script to monitor all out server and pc's on campus. but is there a way to use custom icons on the notification?
Left by Quintin | May 8, 2009
amazing! automate my internet life.
Left by xmoov | May 25, 2009
I get the following error when I try to use this class:
Warning: socket_sendto() [function.socket-sendto]: unable to write to socket [1]: Operation not permitted in /home/onpocom/public_html/class.growl.php on line 127
Warning: socket_sendto() [function.socket-sendto]: unable to write to socket [1]: Operation not permitted in /home/onpocom/public_html/class.growl.php on line 127
Any ideas?
Left by Bondi | Jul 9, 2009
Socket errors are normally caused by the host not allowing the connection (either TCP or UDP). It's a fairly common setup for a shared hosting environment to limit these socket connections.
Left by Mark Neidlinger | Jul 9, 2009
I've got a problem where i'm trying to make a notification sticky and its not working, the notification still happens and I have "Application decides" set up within my prefs,
$growl->notify("Hello", "Hello Alert", "The body of the hello alert!", 2, true);
2 being priority and true being make it sticky, can you offer me any help? Am i just missing something obvious?
Cheers
Left by DanJ | Apr 13, 2010
Thanks for catching that Dan - there's a very good chance it's a bug. Seeing as how bugs aren't allowed in my code, I'll have to remedy that...
Left by Nick Williams | Apr 20, 2010
Hello Nick,
big thanks for you work. Your script worked like a charme and the inline-documentation is very helpfull. Everything is running fine, exept the sticky-bug, wich is also remarked by DanJ. Is any solution out there? Thumbs up.
Greetings,
Martin
Left by Martin | Jun 7, 2010
Great post... never come accross such Idea before.. its very nice to know keep posting more. This script worked superbly.. Great work
Web development Company
Rightway solution
Left by Web development Company | Jul 14, 2010
I can't get this to send mysqlf growl notifications. When I use 127.0.0.1, or localhost nothing happens (no error or notification), if I use my dns alias I get an error (Host lookup failed [-10001], line 127). Looking through the comments I'm not the only one to have this problem, anybody get it to work?
Left by LividChihuahua | Nov 3, 2010
Regarding:
Warning: socket_sendto() [function.socket-sendto]: unable to write to socket [1]: Operation not permitted in /home/onpocom/public_html/class.growl.php on line 127
I found this:
http://www.vbforums.com/showthread.php?t=391569
Changed 0x100 to 0x0 and it worked perfectly. Don't know why or how. Don't know if I've opened up some security problem, but it worked.
Thanks for the cool class.
Left by Steve Adams | Nov 21, 2010
Love it - thank you!
Left by James Morrish | Feb 10, 2011
having the same problem as LividChihuahua. I'm not getting a growl notification or any error when i'm testing it on my local machine. can anyone help?
Left by Kerron | Apr 2, 2011
This is great indeed and I appreciate it that you goer shared quite handy post with the readers of this blog.
Left by PHP Web Development | Apr 4, 2011
I'm having the same issue; no growl notification and no error. I'm running Growl v1.2.1 on OS X 10.6 and calling the php script from the terminal window.
Has anyone figured this out? I will keep searching for a solution and report back if I find anything.
Left by Geoff | Apr 16, 2011
Ok, I was able to get this working with Growl v1.2.1 on OS X 10.6. I had a couple of blocking issues, here is the working setup:
1) Library from authors website: http://clickontyler.com/php-growl/
2) In the Growl settings you must check the following under the "Network" tab:
"Listen for incoming notifications"
"Allow remote application registration"
3) Enter a password in the "Server Password" box, and enter that same one in the test code.
4) Test code (with your own strings, $growl_alert_name can be anything):
$growl = new Growl($growl_ip, $growl_password);
$growl->addNotification($growl_alert_name);
$growl->register();
$growl->notify($growl_alert_name, $growl_title, $growl_message);
Also make sure your firewall settings are in order.
Left by Geoff | Apr 18, 2011
Hi,
Script looks great (after changind 0x100 by 0x0), application is registering, but can't receive notification...
No error in log.. Could you help please?
Thanks,
Mat
Left by Mat | Jun 8, 2011
Hello everyone Script looks great after changing application is registering, but can't receive notification
no error in log........ you help please?
Thanks.
Left by Joomla Customization | Sep 2, 2011
Hi, while this works flawlessly on a local server, i cant figure out so far how to set an external server to trigger a notification on a remote machine behind a router. And after all, thats where it should become handy: to allow your webserver to notify on your desktop for events... no ?
If i use my public IP address in the server-side script, how do the notification request find my computer behind the router ? umh ?
I am probably good enough at php but missing some basic understanding about networking...
If someone can point me to the right direction i will be more than happy to hear that this is possible ;-)
Left by Laurent | Nov 5, 2011