views:

192

answers:

2

I am using the comet long-polling technique with apache, php, jquery.

I've got a basic comet update running and it works great. I'm now attempting to build a more complex comet script, and I want a better way to debug.

My comet scripts use $.ajax() with a long timeout, and the server side just sleeps until it either runs up to the timeout or has an event to send to the client. The comet requests go to a different subdomain than the main ajax requests.

For normal pages I edit and test on a linux laptop. I've got apache, mysql, and php with a test database and mirror image of the site. I can edit, save, and see the changes with no upload step. For the comet stuff I've been having to upload to a server to test. This requires me to set up a few fake servers, but mostly it requires me to upload changed files for each test. I've got a mostly automatic upload script, but it's still too slow.

The problem testing locally is the long timeout. The browser won't open another connection to the same server while the comet request is still open. I don't have a subdomain locally so I have all the requests going to the same server so they basically block each other.

I've tried a number of things to make this work and none really do it. I tried first to change my browser setting for number of simultaneous connections. This didn't work in firefox on linux, and I didn't find anything about changing this limit on other browsers.

I tried setting my hosts file to give me two names that map to my ip address. Then I tried configuring VirtualHost conf directives in apache, but that didn't work. I think because apache is looking for an actual dns server to tell it the hostname, not just my /etc/hosts file. Maybe I can run a local dns server to fool apache into thinking my box has two names, but that just seems like a real long way around this problem.

So, does anyone have an idea of how to make this work on one ip address/host?

I'm new to the comet thing, so maybe I've just got the wrong idea about something. Maybe this isn't even possible. Either way, it's time to just ask if this is already a solved problem.

+2  A: 

It really should be possible to use /etc/hosts to fool Apache. It certainly does work on Ubuntu Hardy with Apache 2.2.

Try to give different hostname to you local address. Simply add a line like this to /etc/hosts:

127.0.0.1    a.example.com b.example.com c.example.com d.example.com

(Note: use a tab after IP)

Validate this with a ping

ping a.example.com

In you apache configuration, you may use a wildcard alias together with a named virtual host:

<VirtualHost *:80>
  ServerName example.com
  ServerAlias *.example.com
  ## snip ##
<VirtualHost>

Instead of using example.com, you might want to use something that's under your control. I use local subdomain of our company's domain (i.e. something.local.molindo.at).

Now you can use different subdomains for your test, each with its own limitation on concurrent connections.

You may need to restart your browser to get this working.

sfussenegger
I'm still not sure I understand the NameVirtualHost and VirtualHost directives, but I've got it working. Thanks!
Mnebuerquo
A: 

I have made something similar and my hosting gives my max queries limit reached which actually should not happen. But I have read that if my php code is in infinite loop.. ie the sleep mode the hosting detects it and makes db connection user as to be using more queries than allowed. That is alot to presume but I have found a solution to that with same speculations.

Kapil Reddy
I'm not sure I understood that, but this isn't a hosting problem. It's a limitation of the browser.
Mnebuerquo