参考代码
?
class="php"><?php
ini_set("display_errors", "On");
/*输出内容函数*/
global $echo_msg_head;
$echo_msg_head = null;
error_reporting(E_ALL);
for( $i=1; $i<=10; $i++ ){
echo_msg('第 '.$i.' 次输出https://dev.xiaoshanwenlv.yocent.cn/test.php https://dev.xiaoshanwenlv.yocent.cn/test.php.');
sleep(1);
}
function echo_msg($str, $color = 'red', $echo = true, $end_str = '')
{
if ($echo) {
if (!isset($GLOBALS['echo_msg_head'])) {
$GLOBALS['echo_msg_head']=true;
header('Content-type: text/html; charset=utf-8');
header('X-Accel-Buffering: no');
ini_set('output_buffering', 'Off');
ob_end_clean();
ob_implicit_flush(true);
$outputSize=ini_get('output_buffering');
$outputSize=intval($outputSize);
if (preg_match('/\biis\b/i', $_SERVER["SERVER_SOFTWARE"])) {
if ($outputSize<1024*1024*4) {
$outputSize=1024*1024*4;
echo '<!-- iis默认需输出4mb数据才能实时显示-->';
}
}
// var_dump($outputSize>1024*1024);
echo '<style type="text/css">body{padding:0 5px;font-size:14px;color:#000;}p{padding:0;margin:0;}a{color:#aaa;}</style>';
$allowOutput=true;
if ($allowOutput) {
echo str_pad(' ', $outputSize>1050?($outputSize+100):1050);
}
}
echo '<p style="color:'.$color.';">'.$str.'</p>'.$end_str;
if (ob_get_level()>0) {
ob_flush();
flush();
}
}
}
//
//header('Content-Type: text/event-stream'); // 以事件流的形式告知浏览器进行显示
//header('Cache-Control: no-cache'); // 告知浏览器不进行缓存
//header('X-Accel-Buffering: no'); // 关闭加速缓冲
//
//$buffer = ini_get('output_buffering');
//$outputSize=intval($buffer);
//for($i=0;$i<10;$i++){
// echo str_repeat('1',$outputSize).$i;
// sleep(1);
// ob_flush();
// flush();
//}
//
//$buffer = ini_get('output_buffering');
//echo $buffer;
//
//echo str_repeat(' ',$buffer+1); //防止浏览器缓存
//ob_end_clean();
//ob_implicit_flush(1);
////ob_end_flush(); //关闭缓存
//
//for( $i=1; $i<=10; $i++ ){
//
// echo '第 '.$i.' 次输出.'."
//\n";
//
// ob_end_flush();
// ob_flush();
// flush();
//
// sleep(1);
//
//}
echo '输出完毕!';
?
?
如果nginx转发过来的网站,在转发配置里,要关闭?proxy_buffering off;
?
server
{
listen 443 ssl;
#listen [::]:80;
server_name dev.xiaoshanwenlv.yocent.cn;
index index.html index.htm index.php default.html default.htm default.php;
ssl on;
ssl_certificate ../cert/4030331_dev.xiaoshanwenlv.yocent.cn.pem;
ssl_certificate_key ../cert/4030331_dev.xiaoshanwenlv.yocent.cn.key;
ssl_session_timeout 5m;
ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_prefer_server_ciphers on;
location / {
proxy_set_header Host $host;
proxy_set_header Server-Port 443;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-Server $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_buffering off;
proxy_pass http://dev.xiaoshanwenlv.yocent.cn:8888;
}
access_log /home/wwwlogs/dev.xiaoshanwenlv.yocent.cn.log access;
}
?
?
相关知识
PHP输出缓冲(output buffer)初级理解和应用?http://niliu.me/articles/605.html
Nginx配置转发?https://www.cnblogs.com/chefweb/p/10725090.html