1

Currently I am using Web Application(LAMP stack) with REST API to communicate with clients(Python Desktop Application).

Clients can register with server and send states to server through REST API.

Now I need to push notifications to selected clients from web application(server).

My question is how can I send push notifications from server(php) and read it from clients(python).

4

2 回答 2

2

There are many ways for this, and most will involve some kind of presistent connection between your server and the clients.

If the desktop client communicates over HTTP, you can use Server Sent Events, websockets or implement some long polling to push notifications.

You can also use a third party services that provide push notifications.

于 2013-07-18T10:33:03.933 回答
1

So basically you can query your server from client in some interval (interval ~ 0 == realtime) and ask, if it has some news.

Normally apache can't deal with long waiting connection, because of its thread/fork request processing model.

You can try switch to nginx, because it is using socket multiplexing (select/epoll/kqueue), so it can deal with many concurrent long waiting connections).

Or you can think about node.js and replace your php app with it, which is absolutely done for this purposes.

Nice solution is too some web framework/language + redis pub/sub functionality + node.js. You can normal requests your web application, but have too open connection to node.js server and node.js server will notice your client when needed. If you want to tell node.js about informing some clients, you can do it from your web app through redis pub/sub.

于 2013-07-18T09:36:20.880 回答