如何判断该函数是否是从输出缓冲回调中调用的?
在函数中,如何确定它是否是从输出缓冲回调中调用的(不一定是直接调用的)?
function foo() {
if (magic here ????)
$log->write("foo:Callback")
else
$log->write("foo:Normal")
}
function calls_foo() {
...stuff
foo();
}
calls_foo() // should log foo:Normal
ob_start('calls_foo')
...stuff
// should log foo:Callback at the end of the script
In a function, how can I find out if it's been called from an output buffering callback (not necessarily directly)?
function foo() {
if (magic here ????)
$log->write("foo:Callback")
else
$log->write("foo:Normal")
}
function calls_foo() {
...stuff
foo();
}
calls_foo() // should log foo:Normal
ob_start('calls_foo')
...stuff
// should log foo:Callback at the end of the script
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
检查
$debug = debug_backtrace()
。如果调试数组的长度为 1,那么您会从 main 调用,这意味着这是在请求结束时调用的 ob 回调。然后,您可以迭代该数组并查看每个数组的'function'
键以获取 ob 刷新函数。Check
$debug = debug_backtrace()
. If the debug array is 1 long then you get called from main which means this is an ob callback called at the end of the request. Then you can iterate the array and look at the'function'
key of each array for an ob flushing function.函数 ob_get_status() 返回一个包含以下信息的数组输出缓冲的当前状态。
The function ob_get_status() returns an array containing information on the current status of output buffering.