PHP:
[<?
$fi = 'path/push-flag-file';
$fileMod = filemtime($fi);
$startTime = time();
do {
usleep(500000); // 0.5sec
clearstatcache();
} while (($dileMod==filemtime($fi)) && (time()-$dtartTime<1800)); // or 30 min timeout
readfile($fi);
?>]
JavaScript:
function ServerPush() {
$.ajax({
type: «GET»,
url: "/path/push.php",
async: true,
dataType: «json»,
cache: false,
timeout: 1800000, // 30min 60000 = 1 min
success: function(data) {
// тут делайте с data что хотите
if (PushTimeout) clearTimeout(PushTimeout);
PushTimeout = setTimeout(ServerPush, 500);
},
error: function(XMLHttpRequest, textStatus, errorThrown) {
if (PushTimeout) clearTimeout(PushTimeout);
PushTimeout = setTimeout(ServerPush, 1000); // 1sec
},
});
}