I would like to implement a mechanism which will provide a RESTful API that allows a client to register interest in a subject with a sever, and receive asynchronous notifications from the server after the interest is registered. In enterprise (messaging) architecture, this is known as publish/subscribe 'pattern'.
With desktop applications, this is readily acheivable - however with web applications, it is proving to be more difficult.
is there a (preferably open source) framework or library out there that allows the publish/subscribe pattern to be applied to web applications?.
Server side technology may be in any of the following languages: C, C++, PHP, Python, Ruby.
I am running on Linux Ubuntu 10.0.4
Have a look at the pubsubhubbub protocol: http://en.wikipedia.org/wiki/PubSubHubbub
Here is the source of the project: http://code.google.com/p/pubsubhubbub/
If you know in advance you'll have a lot of subscribers (people/applications) that want notifications on a certain subject while on other hand you'll have few different subjects consider a pull technology anyway.
RSS, Atom are quite successful even though they use pull. The reason: no need to have an administration on the server of people who are subscribed, to detect who is no longer interested (client offline for a long time) or having a mechanism to get all the data out to the subscribers.
Using push, you need to do very little on the server, while the clients will only pull a small amount of data everytime.
Pull costs slightly more bandwidth that's cheap anyway while it saves you a lot on CPU and software maintanance which is quite expensive.
I suggest you take a look at STOMP protocol, and its python clients (I use stomp.py). That should suit all your needs.
Related
I've been "recruited" so to speak to help work on a web project that is currently written in PHP with an Apache server. We would like to integrate a real-time (or at least something very close to it) chat feature. Scalability is a definite concern, and this type of work is definitely not my typical.
Everything I've read about creating such a chat feature requires the use of "long-polling" so the servers don't get rapidly overloaded and, well, crash. PHP and Apache are not conducive to implementing such a feature, so I've explored some alternatives, like Twisted Python for example.
The website has roughly ~7,000 lines of PHP (i.e., it'd pretty difficult to just straight switch languages for the entire thing), so my question is how can I manage this situation as far as trying to integrate python and setting up a separate server? Or, is this a very bad way to do this? Are there other alternatives that would be better suited? (Sadly many of the PHP Comet, or even AJAX, solutions I've found don't scale in the slightest. Note, the Apache server is not necessarily required; however, any server used must work with PHP and Python etc, short of having separate servers.)
Thanks for the help!
I would use Tornado on the server to write the chat application. Client server communication can then be over websockets. If you use SockJS on the client side you can also support older browsers via long polling. There are plenty of example chat clients written using Tornado. It's very simple to get started and it is wonderfully scalable. A chat server like this can be serving thousands of clients without showing any appreciable CPU activity.
This is an example, possibly a bit over engineered https://github.com/diggidanne/websocket-chat/blob/master/server.py
I want to implement a chat system for my site. The functionality will be very similar to facebook chat. The chats will be one to one based.
I know how to build the chat system using PHP, MySql and using JQuery. But my concern is that it won’t scale to large number of users in the long term.
Using JQuery I would be making requests every second to keep the chat window updated or if the user is sending a request to chat with another user. This will cause extra load on the server as the user base will increase overtime.
I’ve been told using PHP for this is not a ideal solution, that I should look into comet programming, which I never tried before.
My question is that are there any pre-build frameworks out there that I could use, or a better approach of building it?
I heard of NodeJs and APE but these are not supported by my server.
Thanks guys.
EDIT: after having word with my server guys, i might change my OS so i can run NodeJS.
How good is nodejs is term of scalability and will it meet my needs?
PHP and Comet are not mutually exclusive. Comet is just a technique of server push, so you don't have to poll ever second. You implement Comet in PHP & JS, it is not a separate programming language.
Although: I DO NOT recommend programming chat on your own, unless you need very specific features. It is time consuming and error prone. Use one of the pre-made solution, for example:
http://www.phpfreechat.net/
or java IRC chatroom. Google for more.
As Rok Kralj says Comet is a paradigm and can be applied to different technologies. The PHP & Comet question is a good place to start if you want to look into this.
It tends to be commonly agreed that PHP doesn't scale too well as a realtime technology. Facebook, who are a PHP house (although ended up compiling their PHP down to C (or maybe C++) for efficiency). The most common solution is to use dedicated realtime technology for your realtime communication and keep this outside of your web server.
In terms of technology choice I would consider WebSockets since they have become the standard for realtime bi-directional communication. Some 'Comet' servers use WebSockets as a transport too and fallback to the less efficient HTTP Streaming or HTTP Long-Polling for older browsers.
If you'd consider using a hosted service, and don't want to be tied to just chat functionality, would like realtime notifications, visual collaboration or gaming to be added to your app at some point, then http://pusher.com, who I work for, offer a hosted realtime messaging service which you can easily implement your chat functionality.
I'm looking for a COMET server, i want to push messages from the server specifically to some users with some id's, i'm using php and i'm looking for a good and easy COMET server.
Could you tell me which one is the best?
This is subjective without more details. We've looked at APE, Node.js implementations, and others- all offer slightly different strengths / weaknesses.
If you're only interested in the functionality and don't want to develop the competencies or own the responsibilities of managing your own comet server there are fairly mature 'Comet' as a service offerings. I've used Pusher on a recent project, it delivered everything we needed and might be a good place to start.
The choice of the comet server depends on the kind of app you are developing. If you have plans of porting your app to mobile platforms in the future , then you can go for WebSync. This is simple to use, provides a simple API for you to publish from a javascript client, from PHP, from iOS client and also from a .NET client. Also, you can use Websync either as a server or on-demand. But, the thing is, WebSync's free version allows only upto 10 concurrent clients. If you want more, you will have to purchase.
I have also looked a little bit into APE. This is completely open source and all your code has to be written in Javascript which may be a little inconvenient in some cases. Make your choice depending on your needs
I highly recommend you to use APE
http://www.ape-project.org/
Reasons :
http://www.ape-project.org/ajax-push.html
I'm working on a PHP application and I'm looking for some ideas for a real-time protocol that I can use for:
1) track users status and location within the application (this should be fast!!!)
2) chat system.
I'm looking for something like FMS and its "Shared Objects" where multiple users can subscribe to pieces of information. FMS is expensive and slow for what I need, I would need a widget loaded on each page, requesting a new connection to the FMS server, etc.... slow...
I need something fast, ope source would be perfect!. Something like what Google Waves uses for syncing shared documents.
Any suggestions?
If you are willing to write this in PHP, I'd say you are looking at the wrong technology. There is 2 major problem with PHP and real-time.
When you run a PHP application, it is not persistant like Servlet with Java. It is hard and not really adapted to do communication between each connection. You have to use database storage, stream or file to send data between each instance. All of these methods are not very efficient.
It is using blocking I/O and this is where it hurts in term of performance and scalability.
You should look at non-blocking I/O technology for web server. They are all event-driven server which is something different from the PHP approach. Here are few example :
JBoss + Netty (Java)
Node.js (Javascript) - Google Tech Talk about it
Twisted (Python)
You need websockets or something similar.
http://www.orbited.org/
"Orbited allows you to write real-time web applications, such as a chat room or instant messaging client, without using external plugins like Flash or Java. It enables streaming networking for JavaScript without loading bars or page refreshes."
You can implement the chat as IRC or Jabber using Orbited.
So I am thinking about creating a multiplayer game and I was wanting to use php because I already have a php server. Is it possible to make a socket server that will be able to handle a actionscript multiplayer game. The game won't be big. so we wont need any huge amount of data pushing through. just some software that is probably reliable enough to run a multiplayer game.
PHP is clearly not a solution when it comes to socket server. It's simply not meant for that kind of usage.
If you really want to go multiplayer, SmartFox ( http://www.smartfoxserver.com/) offers a professional solution when it comes to Flash. After that developing a small socket server in a proper language is not that complicated, and the possibility are endless (Python, Java, C#, C, C++, Erlang, Go, Erlang, ...). It really depends on what kind of game you're want to do.
PHP could be eligible as a solution in case of turn by turn type game, you could simply handle it as a RESTful service (sending back and forward the game state by http).
You could use PHP, but I wouldn't recommend it. In addition you will need a shell on your server and the ability to execute custom servers, since the PHP socket server will not be running from inside the webserver (Apache etc).
I would recommend one of the many realtime communication servers available for Flash, such as Wowza, ElectroServer, Union, or others (just google for them)
There are some free ones available too, but the quality may not be as good. Some examples I found with a 30 second google serach, I know nothing about them: Oregano, GFS, Palabre
You could use Red5. It's an open source Java implementation of a Flash Media Server that allows for what you want to do:
http://osflash.org/red5