<?php |
header( "Expires: Sun, 19 Nov 1978 05:00:00 GMT" ); |
header( "Last-Modified: " . gmdate ( "D, d M Y H:i:s" ) . " GMT" ); |
header( "Cache-Control: store, no-cache, must-revalidate" ); |
header( "Cache-Control: post-check=0, pre-check=0" , FALSE); |
//在$timeout之后,关闭连接,并且要求客户3秒后重新请求 |
for ( $i = 0, $timeout = 60; $i < $timeout ; $i ++ ) { |
$msg = get_msg(); |
if ( $msg ) { |
echo json_encode( array ( 't' => 'info' , 'c' => $msg )); |
flush (); |
exit (0); |
} |
usleep(3000000); |
} |
echo json_encode( array ( 't' => 'refresh' , 'c' => 3000)); |
flush (); |
?> |