I apply comet long polling which uses usleep inside while loop until no new data returned by server like below:
PHP
while ($currentmodif <= $lastmodif)
{
usleep(10000); // sleep 10ms to unload the CPU
clearstatcache();
$currentmodif = filemtime($filename);
}
My ajax call has timeout specified:
jquery
var timeout = 120;
jQuery.ajax({
method: "POST",
url: "/index.php",
timeout: 1000* timeout, // 1000 1 sec
"data": data2,
error: function() {
console.debug('error');
},
success: function(result) {
..........code cut for brevity...
so when the while loop reaches php.ini max_execution_time
, ajax will timeout and start a new connection.
This works well thus far. My only concern is will this method eat up disk space or slow down the system's performance? If yes, how to overcome it..
Please don't advise to shift to websocket
as I don't own the server..so I can't make any changes to it..