【问题标题】:ob_flush() working on localhost but not online at GoDaddyob_flush() 在 localhost 上工作,但在 GoDaddy 上不在线
【发布时间】:2017-06-05 23:29:42
【问题描述】:

我有以下 PHP 脚本:

<?php 
ob_end_flush();
ob_start();
for ($i=0; $i < 10; $i++) {
    echo "Line ".$i."</br>";
    ob_flush();
    flush();
    sleep(1);
}
ob_end_flush();
?>

它在 WAMP localhost 上运行良好,并且每秒打印新行,但在 GoDaddy 经济主机上在线,它不起作用。它显示了 10 秒后除了页面加载之外什么都没有发生的输出。

可能出了什么问题?

【问题讨论】:

  • 调用函数phpinfo();在一个单独的 php 脚本中并在您的主机服务器上运行它以查看是否在 GoDaddy 的主机服务器中启用了 ob_flush()
  • 究竟启用了什么?
  • output_buffering = On,或者 output_buffering=4096 应该在 PHP.ini 中设置而不是 output_buffering = off
  • 两种方法都试过了,都不行。

标签: php linux buffer flush server-configuration


【解决方案1】:
It will work fine....

if(!ob_get_level()) ob_start();
echo json_encode(array('valid'=>true,'msg'=>'Flush occured.'));
$size = ob_get_length();
header("Content-Type: application/json");
// Set the content length of the response.
header("Content-Length: {$size}");
//Close the connection if you want to.
header("Connection: close");
// Flush all output.
ob_end_flush();
ob_flush();
flush();
// Close current session (if it exists).
if(session_id()) session_write_close();

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-06-12
    • 2021-11-01
    • 1970-01-01
    • 1970-01-01
    • 2018-09-25
    • 2015-11-22
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多