且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

来自Web服务器的低吼通知

更新时间:2023-02-16 21:49:22

GNTP (各种语言的增长网络传输协议)绑定,可以在此处找到绑定列表-这些允许您从PHP脚本发送通知.

There are GNTP (Growl Network Transport Protocol) bindings for various languages, a list of bindings can be found here - these allow you to send notifications from, say, a PHP script.

我不会直接信任Growl的UDP系统,而是编写一个服务器来接收和存储通知(也许是一个小型的Web应用程序),以及一个本地脚本,该脚本通常会通过HTTP抓取任何新消息并将Growls接收.一点也不复杂,它将比UDP更可靠,并且可以在Growlinging机器断电或无法访问时将消息排队.应该花很长时间来实现

I wouldn't trust Growl's UDP system directly, but rather write a server that receives and stores notifications (maybe as a tiny web app), and a local script that routinely grabs any new messages via HTTP and Growls them. Not complicated at all, will be more reliable than UDP, and can queue up messages when your Growl'ing machine is powered-off or unreachable. Shouldn't take long to implement

基本上是伪PHP中的server.php(可以使用 Net_Growl ):>

Basically, server.php in pseudo-PHP (which could use Net_Growl):

<?php
if($_GET['action'] == "store"){
    $title = $_POST['title'];
    $message = $_POST['message'];
    $password = sha1($_POST['password']);
    if($password == "..."){
        store_in_database(sanitise($title), sanitise($message);
    }
} else {
    print(json_encode(get_notifications_from_database()));
    mark_notifications_as_read();
}
?>

client.py在伪Python中(可以使用 gntp ):

client.py in pseudo-Python (which could use gntp):

while 1:
    time.sleep(60):
    data = urllib.urlopen("http://myserver.com/server.php?action=get&password=blah").read()
    for line in data:
        notif = json.decode(line)
        growl.alert(notif['title'], notif['message'])