Welcome Guest, Not a member yet? Register   Sign In
CodeIgnitor with Comet Server
#1

[eluser]Unknown[/eluser]
I was wondering if anyone would be able to provide with recommendations on using a Comet server with CodeIgnitor? What are the best Comet Servers to use with CodeIgnitor?
#2

[eluser]gazugafan[/eluser]
I just ran some tests using SimpleComet. It was easy to integrate into CodeIgniter as a library. You basically just setup a controller with a big loop that runs as long as you like, so CodeIgniter IS the server! I haven't done any scalability testing yet, but so far so good...
http://mandor.net/2008/12/23/12-simpleco...-scrubbing

The problem I'm having right now is that whenever I open a second tab, it seems like the script hangs and doesn't respond, or it hangs for a long time before responding. I came across the following, which I'm hoping points me in the right direction...
http://gonzalo123.wordpress.com/2010/04/...t-and-php/
#3

[eluser]gazugafan[/eluser]
It's been awhile, but for the sake of others looking at this, here's what I came up with...

The SimpleComet solution scaled miserably and I never did get around the problem I was having. I also really wanted a more event-driven approach than the "keep polling the database for changes" approach that would be necessary with SimpleComet.

I knew before getting into this that PHP wasn't a popular choice for comet, but the real reason PHP sucks for this is that it's typically running on Apache. Apache eats up a good chunk of memory with each request, and doesn't free it until the request is over. So, if you start getting more than a just a few long-polling AJAX requests going at the same time, your server starts moving at a snails pace really quick. I was determined to make it work, though, and I did! The solution is a little tedious to setup, but it integrates so elegantly with CodeIgniter you'll be glad you spent the time to do it. And it really isn't THAT difficult. You just need to setup a new server, and once it's done the actual code is dead-simple. Here's the solution...

You need to ditch apache and go with NGINX--a super efficient web server designed with this scalability problem in mind. You can setup NGINX to run PHP in fast-cgi mode. However, you'll also need a special module for NGINX called the NGINX_HTTP_Push_Module. To do this, you'll need to compile NGINX from source along with NGINX_HTTP_Push_Module.

Once you've got it all setup, use javascript to create "subscribers" to an NGINX_HTTP_Push_Module channel. These are really just long-polling AJAX requests to a specific URL that NGINX_HTTP_Push_Module is configured to work with. No PHP script or file is contained there at all. NGINX_HTTP_Push_Module just works with it and handles all of the message routing automatically. These AJAX subscriber requests then wait for a message to be published to the channel, and your response event will handle the messages however you want.

To publish messages, you don't NEED to use PHP at all, actually. Anything that can post data to that configured URL (there's actually a second URL--one for publishing and one for subscribing) can send messages to the subscribers. However, you can easily do this from within PHP just by using curl. So, in the codeigniter controller that would normally save a new message for your old polling scripts to catch, just use curl to publish the message to any subscribers that are listening. Voila! No more polling. It's PHP Comet that should scale awesome.

A few links that should help you hash this all out:
http://wiki.nginx.org/Main
http://pushmodule.slact.net/
http://saul.baizman.net/node/72
http://blog.jamieisaacs.com/2010/08/27/c...nd-jquery/
#4

[eluser]Eric Cope[/eluser]
Could you use PHP-CLI?
#5

[eluser]gazugafan[/eluser]
with NGINX?
#6

[eluser]Unknown[/eluser]
@gazugafan. Your script hangs probably because of sessions not due to comet. I had the same problem and I wrote an article about it: http://gonzalo123.wordpress.com/2010/04/...t-and-php/
#7

[eluser]gazugafan[/eluser]
lol... you didn't notice the link at the end of my reply, then? It's a small Internet afterall Wink

So yeah. Unfortunately, I already went down that path. I had stripped the php script down to the bare minimums--no session handling at all, but never got past that problem. In the end, I'm REALLY glad I took the time to do things "right". The NGINX_HTTP_Push_Module took more time to setup, but the end result is so scalable, simple and elegant that it was WELL worth it.
#8

[eluser]SDSL[/eluser]
[quote author="gazugafan" date="1299583953"]It's been awhile, but for the sake of others looking at this, here's what I came up with...

The SimpleComet solution scaled miserably and I never did get around the problem I was having. I also really wanted a more event-driven approach than the "keep polling the database for changes" approach that would be necessary with SimpleComet.

I knew before getting into this that PHP wasn't a popular choice for comet, but the real reason PHP sucks for this is that it's typically running on Apache. Apache eats up a good chunk of memory with each request, and doesn't free it until the request is over. So, if you start getting more than a just a few long-polling AJAX requests going at the same time, your server starts moving at a snails pace really quick. I was determined to make it work, though, and I did! The solution is a little tedious to setup, but it integrates so elegantly with CodeIgniter you'll be glad you spent the time to do it. And it really isn't THAT difficult. You just need to setup a new server, and once it's done the actual code is dead-simple. Here's the solution...

You need to ditch apache and go with NGINX--a super efficient web server designed with this scalability problem in mind. You can setup NGINX to run PHP in fast-cgi mode. However, you'll also need a special module for NGINX called the NGINX_HTTP_Push_Module. To do this, you'll need to compile NGINX from source along with NGINX_HTTP_Push_Module.

Once you've got it all setup, use javascript to create "subscribers" to an NGINX_HTTP_Push_Module channel. These are really just long-polling AJAX requests to a specific URL that NGINX_HTTP_Push_Module is configured to work with. No PHP script or file is contained there at all. NGINX_HTTP_Push_Module just works with it and handles all of the message routing automatically. These AJAX subscriber requests then wait for a message to be published to the channel, and your response event will handle the messages however you want.

To publish messages, you don't NEED to use PHP at all, actually. Anything that can post data to that configured URL (there's actually a second URL--one for publishing and one for subscribing) can send messages to the subscribers. However, you can easily do this from within PHP just by using curl. So, in the codeigniter controller that would normally save a new message for your old polling scripts to catch, just use curl to publish the message to any subscribers that are listening. Voila! No more polling. It's PHP Comet that should scale awesome.

A few links that should help you hash this all out:
http://wiki.nginx.org/Main
http://pushmodule.slact.net/
http://saul.baizman.net/node/72
http://blog.jamieisaacs.com/2010/08/27/c...nd-jquery/[/quote]

I’ve come across your reply using google search and it was very helpful for me, also by using this module https://github.com/Kronuz/nginx_http_push_module
i was able to add secret word and key to the channel




Theme © iAndrew 2016 - Forum software by © MyBB