是否可以将php脚本将产生的响应保存到一个变量中


is there anyway to save the response my php script will produce into a variable?

我正在构建我自己的API监控工具,我想知道是否可以将要监控的PHP脚本将生成的响应保存到变量中,以便在脚本代码处理完成后将其用于其他内容,类似于脚本顶部的ob_start();

$output = ob_get_contents();
ob_end_clean();

在底部,然后用$output 做我想做的事

这是最好的方法吗?

发现如果我使用ob_get_contents();而不请求ob_start();,它将显示主输出缓冲区值