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 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用
  • ¥15 C++ yoloV5改写遇到的问题
  • ¥20 win11修改中文用户名路径
  • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入
  • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计
  • ¥70 PlayWright在Java上连接CDP关联本地Chrome启动失败,貌似是Windows端口转发问题
  • ¥15 帮我写一个c++工程
  • ¥30 Eclipse官网打不开,官网首页进不去,显示无法访问此页面,求解决方法
  • ¥15 关于smbclient 库的使用