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.
Comet connection keeps closing after every minute.
Moderator: General Moderators
Re: Comet connection keeps closing after every minute.
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.
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.
Thanks man. So I guess:
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.
Code: Select all
ini_set("max_execution_time", 20*60);[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.
- Chris Corbyn
- Breakbeat Nuttzer
- Posts: 13098
- Joined: Wed Mar 24, 2004 7:57 am
- Location: Melbourne, Australia
Re: Comet connection keeps closing after every minute.
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.
I don't think I understand the first sentence. What's inert data, and what's an X-Mixed-Replace entity?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.
Re: Comet connection keeps closing after every minute.
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 Chrome either, but it works in Safari, FF and IE.
There are 10 types of people in this world, those who understand binary and those who don't