duanqian2278 2014-11-08 00:21
浏览 160
已采纳

PHP flush不起作用

I'm trying to get PHP flush working for 2 hours, i can't make it work, in localhost it work, but when i drag it on server it stop working. The code is this:

<?php
  ob_implicit_flush(true);
  ob_end_flush();
  for ($i=0; $i<5; $i++) {
    echo $i.'<br>';
    sleep(1);
  }
?>

I tried a lot of other versions, but all the version i fond work only on localhost (as this), but not on my server, i read somewhere that it would be fixed changing some lines on the php.ini file, but i'm using an Aruba hosting windows domain, so i can't edit the php.ini, how can i do?

Update: I tried it on others two free hosting serice, and it work on them, it's just my main hosting services that do problem: what can it be?
Update: Since a lot of script i found use ini_set I tried to check values that they set, i don't know if they can be useful:
session.use_trans_sid 0 output_buffering 4096 zlib.output_compression Off

  • 写回答

2条回答 默认 最新

  • doushan15559 2014-11-08 01:15
    关注

    This works, but only in a default apache environment:

    <?php
    ini_set('output_buffering', 0);
    ini_set('zlib.output_compression', 0);
    if( !ob_get_level() ){ ob_start(); }
    else { ob_end_clean(); ob_start(); }
    for ($i = 0; $i < 10; $i++) {
      //For Nginx we have to reach minimum  buffer size, 
      //so if it is not enough increment output
      echo str_pad( $i . '<br>', 1024 + 10, ' ', STR_PAD_RIGHT ); 
      flush();
      ob_flush();
      sleep(1);
    }
    

    Nginx needs more configurations:

    usually in /etc/nginx/nginx.conf

    gzip off;
    proxy_buffering off;
    fastcgi_buffer_size 1k;       #set buffer to 1k
    fastcgi_max_temp_file_size 0;
    fastcgi_buffers 128 1k;       #set max buffer size to 1k + 128*1k
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么