首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >强制PHP流php响应

强制PHP流php响应
EN

Stack Overflow用户
提问于 2018-03-14 17:19:40
回答 1查看 857关注 0票数 1

当我在循环中回音时,我需要输出蒸汽。通常情况下,我会把这样的东西

代码语言:javascript
复制
ini_set('output_buffering', 'off');
ini_set('zlib.output_compression', false);

ob_end_flush();
while (@ob_end_flush());

ini_set('implicit_flush', true);
ob_implicit_flush(true);

header("Content-type: text/html");
header('Cache-Control: no-cache');

在页面顶部,然后调用

代码语言:javascript
复制
echo 'Something to print out here';
ob_flush();
flush();

然而,这根本行不通。我没有得到生成的错误,也没有显示它只是在没有缓冲的情况下不能立即输出。这似乎根本没有任何效果。我也尝试过修改php.ini文件。这也没有任何效果。我已经在2种不同版本的PHP桌面上尝试过这一点。我在PHPDesktop47.0Chrome上试用过,它使用的是PHP5.4,也是最新推出的使用PHP 7的PHPDesktop57.0。

UPDATE我收到了来自php桌面开发者的回复,他不知道为什么它不起作用,并建议Mongoose服务器哪个php桌面用户可能不支持这一点。会有比我更多的经验吗?除了使用php桌面之外,我从未真正使用过它。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-03-14 21:23:18

要使输出缓冲区刷新在Mongoose中工作,诀窍是在调用ob_flush / flush之前总共输出8192个字符。下面的示例代码,阅读php注释和html注释获得更多细节。

代码语言:javascript
复制
<?php

error_reporting(-1);

ini_set('zlib.output_compression', 0);
ini_set('output_buffering', 0);
ini_set('implicit_flush', 1);

// This buffer length value is copied from "mongoose.c" file.
// If you would like to reduce buffer size then modify "mongoose.c"
// file and rebuild phpdesktop from sources.
define("MG_BUF_LEN", 8192);

function fprint($s)
{
    $args = func_get_args();
    call_user_func_array('printf', $args);
    print(str_repeat(" ", MG_BUF_LEN));
    @ob_flush();
    flush();
}

header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
header("Cache-Control: no-cache, no-store, must-revalidate");
header("Pragma: no-cache");

?>

<style type="text/css">@import url("style.css");</style>
<a href="index.php">Go back to index</a>
| <a href="<?php echo $_SERVER["REQUEST_URI"];?>">Refresh</a>

<title>Output buffer flush</title>
<h1>Output buffer flush</h1>

<p>
    This example forces flush of output buffer repeatedly.
</p>
<p>
    This technique works differently with Mongoose web server.
    Mongoose forces to always read 8192 characters (MG_BUF_LEN)
    before sending output. The solution is to output 8192 spaces
    before each ob_flush / flush calls. Spaces are ignored in html,
    so this output is not visible. It should really be 8192
    characters minus characters previously outputted for it to
    work always correctly. In this simple examples this is not
    required.
</p>

<?php

fprint("\r\n\r\n");
sleep(1);
fprint("Slept for 1 second<br>");
sleep(2);
fprint("Slept for 2 seconds<br>");
sleep(3);
fprint("Slept for 3 seconds<br>");
fprint("Done.")

?>

我已经将"ob-flush.php“示例介绍到php桌面:

https://github.com/cztomczak/phpdesktop/blob/2a800fecd8830e4f1e6c4054e74e8d03b4900847/phpdesktop-chrome57/www/ob-flush.php

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/49284023

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档