123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354 |
- <?php
- //// 确保在刷新或者调用ob_end_flush()函数后,数据立即被发送到浏览器
- //if (function_exists('apache_setenv')) {
- // apache_setenv('no-gzip', '1');
- //}
- //
- //ini_set('zlib.output_compression', '0');
- //ini_set('implicit_flush', '1');
- //
- //for ($i = 0; $i < ob_get_level(); $i++) { ob_end_flush(); }
- //ob_implicit_flush(1);
- //
- //// 发送适当的HTTP头信息
- //header('Content-Type: text/event-stream');
- //header('Cache-Control: no-cache');
- //header('X-Accel-Buffering: no'); // 如果使用Nginx,确保Nginx不会缓冲此请求
- //$i = 0;
- //while ($i < 5) {
- // $i++;
- // $time = date('Y-m-d H:i:s');
- // echo "data: {$time}\n\n";
- // flush();
- // sleep(1);
- //}
- //?>
- <?php
- // 确保在刷新或者调用ob_end_flush()函数后,数据立即被发送到浏览器
- if (function_exists('apache_setenv')) {
- apache_setenv('no-gzip', '1');
- }
- ini_set('zlib.output_compression', '0');
- ini_set('implicit_flush', '1');
- while (ob_get_level() > 0) {
- if (!ob_end_flush()) {
- break;
- }
- }
- ob_implicit_flush(1);
- // 发送适当的HTTP头信息
- header('Content-Type: text/event-stream');
- header('Cache-Control: no-cache');
- header('X-Accel-Buffering: no'); // 如果使用Nginx,确保Nginx不会缓冲此请求
- $i = 0;
- while ($i < 5) {
- $i++;
- $time = date('Y-m-d H:i:s');
- echo "data: {$time}\n\n";
- flush();
- sleep(1);
- }
- ?>
|