After long searching of comet server, i choose orbited comet server.
I have to build a real-time chat system in PHP using Orbited Comet Server and Stomp PHP client.
It does not handle hundreds or thousands of simultaneous connections.
How could i solve this problem? Is there any other library to add for fix this problem?
Thanks.
My Regards
Unfortunately this is a problem I have wrestled with for quite a while in PHP, specifically for the same kind of usage scenario. The only possible solutions I have come up with so far are these:
1) Implement another comet server other then orbited, and build it with that kind of load in mind, with an eye toward using the cloud for quick server standup.
2) using a stable messaging fabric such as the ones already implemented in Java in order to add to the performance side of things, while having to handle it properly with my own php library.
Both of these solutions have their own ups and downs, but I feel that in the end, implementing such a server in PHP, or with the existing oss solutions that I know of, would be futile for high volume communications.
Related
I have a fairly big web application build with SproutCore and PHP as backend. What I want now is to use websockets to update my client application in real time.
From what I know, PHP is really bad to handle persistent connections. So I've been thinking that I could use Go to handle the websockets connections and call my PHP scripts each time a request is received (this package seem to make it possible).
So my first question is, do you guys think it's a good idea (and a viable idea, I haven't been able to find people doing so) or should I stick with PHP ?
If I use Go to handle the websockets connections I've also been thinking that I could progressively move away from PHP to only use Go (since it is a lot faster than PHP). If I do that, I will have to be able to call some Go package from PHP. Can this be done with the PHP exec function ? Is there a better way ? And again, is that a good idea ?
Go is a natural fit for websocket servers. I've built websocket servers in Go and have been extremely happy with how it all worked out. I have one service handling 300k users a month on a Go websocket server and it barely uses 1% CPU of an Amazon AWS micro instance. Couldn't be happier.
Websockets really need event driven frameworks like Go and Node.js in order to maximize server resources. Forked web processes like PHP consume far more resources than an event driven framework.
If you need to call Go from PHP at some point, I suggest using API calls. Although exec would work too.
It is an old question, but my two cents on this subject...
There is a very good php library that does exactly what you are asking for - websockets. It is called Ratchet. I would not use node.js (over hyped) or go when php can do exactly the same thing and it is the language that I am most comfortable with. In majority of cases, little gain in performance over websockets is not worth switching stack.
Other useful links if you plan on using Ratchet:
Backend - Ratchet Examples
Frontend - Autobahn WS
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
Is there a real solution for COMET AND PHP combination? Basically, I've come to a point that I need to update a user home page periodically whenever there is new data in the database. As far as I understand, I need to open a persistent connection between my server and my clients browsers to update the contents of their home page as soon as new info. available without dedicating a lot of resources but I had no luck finding anything clear about this issue. I read many articles suggests that PHP is not a good language to implement COMET. My web application is completely programmed in PHP and I don't want to learn another language but if I'm forced to, Would you suggest a good language to start with? Do you think that I can program an interface just to handle this issue?
Thanks in advance.
The times I've heard people say that PHP was not well suited for COMET (like you said yourself) was because of the way webservers and PHP work -- mostly, because there is one process per page, which means if you want 200 users connected to your server, you'll need 200 processes (which can quickly become a problem for a couple of hundred more users).
Maybe a solution to that problem would be to use nginx_http_push_module ?
I've not tried it (yet ?), but it might be just what we need...
I was working on a school project and ran into the exact same problem. Because each PHP process has so much memory overhead, it's impossible to support to many connections per box. It was at this point I decided to switch to using BOSH and XMPP. This is a rather new "wave" of technology but there is already quite a few libraries to help you on your way. I would suggest using Strophe and XMPPHP. Then your clients can connect to a BOSH server (I'm using Openfire) and that can scale to thousands of active connections per server.
You don't have to learn a new language to implement such a feature.
For example, you could use Quercus (Java implementation of PHP) and implement a server Comet application using the JVMs memory management model.
There are solutions you need:
almost COMET solution (uses php and one file written with perl):
http://translate.google.com/translate?js=y&prev=_t&hl=ru&ie=UTF-8&layout=1&eotf=1&u=http://dklab.ru/lib/dklab_multiplexor/&sl=ru&tl=en
exact COMET solution in php (this is what you want, I think):
http://translate.google.com/translate?hl=ru&sl=ru&tl=en&u=http://dklab.ru/lib/dklab_realplexor/
You would first need to understand what is a comet application like. The concept involved in building a comet application are explained at wiki at Comet (programming)
What you need to understand is that you can use any programming language to build a comet application as long as it follows the concepts explained at wiki
1.Ajax with long polling
2.Streaming
You can check some sample code at Simple “Long Polling” example code
Now coming to the problems -
1.You use ajax long polling then the browser(ajax request) would keep polling the server for data. This may eat up memory on the server or slow down the browser after some time.
Few Suggestions
JQuery PeriodicalUpdater (AJAX long polling/server polling)
Handling Long Polling
RobertFischer / JQuery-PeriodicalUpdater
What you need to check to implement this -
a) How often do you expect data to be updated on the server.
b) How much time the server side script would run to check, fetch and process data before sending it to the client side.
2.You can implement streaming by using the following -
How to implement COMET with PHP
Lightstreamer Dojo
Dojo Charting + Lightstreamer Comet Demo
Demo
Ajax Push Engine or The APE Project
What you need to check for this -
a) Will your hosting provider allow you to install these on hosting servers
b) Your RAM and Bandwidth utilization (You will need a dedicated server with package that gives you lots of RAM and Bandwidth)
It depends on what and how your requirements are. You will have to analyze and approach.
If what you are implementing is a small application you can go for Ajax Long polling given the fact that you analyzed and handled the negatives of this approach.
If you have a large application you can go for steaming.
Ajax with long polling is a easy solution, there are plugins in jquery and any other major js framework to help you do this.
Node.js seems like a pretty sweet solution for stuff like this. (Still a little gamey for production but cool all the same). PHP is a horrible environment for stuff like this, you have to change the way the server interacts with requests because you are no longer immediately responding. Python has a handful of servers like Twisted that are great for this because they let you be the server. No matter what language you write it in you've got to alter the typical request/response model. (Glassfish's Grizzly Comet server does this for Java as an example)
You should try Dmitry Koterov's Realplexor, which is a comet server, that provides Javascript and PHP APIs.
Readme.txt in english is provided in the package.