是否可以确定当前代码输出是否正在 PHP 中缓冲?

发布于 2024-10-03 04:14:50 字数 54 浏览 1 评论 0原文

有没有一种方法可以确定文件中随机位置的回显/打印是否正在使用 ob_start 进行缓冲?谢谢

Is there a method to determine, whether the echo/print in a random place in a file is being buffered with ob_start? Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

幽梦紫曦~ 2024-10-10 04:14:51

ob_get_level()将返回当前输出缓冲级别(活动输出缓冲区的数量,因为您可以连续多次调用ob_start()),因此返回值0表示没有活动输出缓冲

ob_get_level() will return the current output buffering level (the number of output buffers active, since you can call ob_start() multiple times in a row), so a return value of 0 means no output buffering is active

当爱已成负担 2024-10-10 04:14:51

您可以使用 ob_get_level() 功能:

<?php
if(ob_get_level() > 0) { 
    // output buffering active
}

You can use the ob_get_level() function:

<?php
if(ob_get_level() > 0) { 
    // output buffering active
}
偏爱你一生 2024-10-10 04:14:51

是的,有...

参见 ob_get_level()

if (ob_get_level() > 0) {
    //Output Buffering Is Active!
}

但请务必阅读该页面上的注释可以了解正在发生的情况,因为某些 php.ini 设置可以在脚本启动之前设置输出缓冲区...

Yes there is...

See ob_get_level():

if (ob_get_level() > 0) {
    //Output Buffering Is Active!
}

But be sure to read the comments on that page for insight as to what's going on, as certain php.ini settings can set a output buffer from before the start of the script...

琴流音 2024-10-10 04:14:51

您可以使用 ob_get_clean() 来查看该缓冲区中隐藏的内容。

You could use ob_get_clean() to see what's hiding inside that buffer.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文