The time-out issue will be caused by your while loop failing to exit before PHP exits because the value of the max_execution_time
directive has been reached. You could extend this, but do you really want scripts to be running for that long? I'd be more inclined to do more work in the JavaScript - make it request an update every second or so (10ms is far, far too often).
Regarding the alert("error")
, be careful where you're setting the value of noerror
- do you really want to set it to false at the end of the complete()
function? I think you want to change your call to $.ajax()
to something more like this (abbreviated):
$.ajax({
error : function() {
// the request failed
setTimeout(function() { comet.connect(); }, 5000);
},
success : function(response) {
// the request succeeded
self.connect();
}
});
If you can, remove the noerror
variable entirely and use the error()
and success()
callbacks to house your logic for each scenario, like above.