Page 1 of 1
Comet connection keeps closing after every minute.
Posted: Mon Mar 09, 2009 5:21 pm
by JellyFish
I am using a long polling comet technique in my application that polls for information from a page which loops forever until it finds new data to send back. Everything works, except it seems that every minute Firefox closes my polling connection; as if there was a limit to how long Firefox waits for a page. It could be something other then Firefox because there's this other comet example/tutorial that doesn't appear to suffer from this issue.
I'm thinking it could either jQuery (which I'm using to make the XHR requests) or it could be my server. If it's my server, which I'm betting it is, then how could I turn off this restriction, if possible? I'm on a shared hosted server, so I believe it to be very plausible that my hosting provider would create this restriction for their costumers.
Has anyone ever had anything similar to this happen? What could be the cause?
Thank you for reading.
Re: Comet connection keeps closing after every minute.
Posted: Mon Mar 09, 2009 5:33 pm
by kaszu
I think it's server. PHP by default has 30 ('max_execution_time' configuration name) seconds, before script is terminated. It can be changed by
ini_set, but it will terminate (by apache?) after some time anyway, last time I tried, I think it was about 10 or 20 minutes.
I usually set few minute period and if after this period there is still no data to send, then close the connection on server. On client side when connection is closed, run another request.
Re: Comet connection keeps closing after every minute.
Posted: Mon Mar 09, 2009 9:03 pm
by JellyFish
Thanks man. So I guess:
Code: Select all
ini_set("max_execution_time", 20*60);
ought to do it.
[EDIT] Actually, it seems as thought it's still closing even with this php statement at the top of my php page. But it's closing at 2 minutes for the first request, and 1 minute on the following requests. Strange.
Re: Comet connection keeps closing after every minute.
Posted: Tue Mar 10, 2009 5:21 pm
by Chris Corbyn
I think you need to find a way to push "inert" data down the connection, such as a header, or an X-Mixed-Replaced entity every 10 seconds or so. Both the browser and the server have timeouts and if the server is not responding the browser will give up.
Re: Comet connection keeps closing after every minute.
Posted: Wed Mar 11, 2009 12:08 am
by JellyFish
Chris Corbyn wrote:I think you need to find a way to push "inert" data down the connection, such as a header, or an X-Mixed-Replaced entity every 10 seconds or so. Both the browser and the server have timeouts and if the server is not responding the browser will give up.
I don't think I understand the first sentence. What's inert data, and what's an X-Mixed-Replace entity?
Re: Comet connection keeps closing after every minute.
Posted: Wed Mar 11, 2009 4:56 am
by VladSun
Code: Select all
set_time_limit(0);
//ignore_user_abort(true);
$waitTime = 1;
$separator = "string_not_presenting_in_data";
$boundary = "\n" . $separator . "\n";
header('Content-Type: multipart/x-mixed-replace; boundary=' . $separator);
header("Pragma: no-store, no-cache");
header("Cache-control: no-cache, no-store, must-revalidate, max-age=-1");
header("Expires: -1");
echo $boundary;
for ($i=0; $i<5; $i++)
{
echo "Content-Type: text/plain\n\n";
echo "#".$i."\n";
echo $boundary;
ob_flush();
flush();
sleep($waitTime);
}
it doesn't work in Opera, though.
It doesn't work in Chrome either, but it works in Safari, FF and IE.