PHP output_buffering只使用error_reporting(E_ALL)问题

问题描述:

我有一个PHP脚本,这是其中一部分:PHP output_buffering只使用error_reporting(E_ALL)问题

if($signature == $params_signature) { 
    error_reporting(E_ALL); 
    ini_set('display_errors', 1); 
    ob_start(); 
    echo 'OK'; // send the OK response 
    header('Connection: close'); 
    header('Content-Type: text/html; charset=utf-8'); 
    header('Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0'); 
    header("Content-Encoding: none"); 
    header('Content-Length: '.ob_get_length()); 
    ob_end_flush(); 
    ob_flush(); 
    flush(); 
    echo 'test'; 
    // some further procesiing 
    exit; 
} 

所以问题是:ob_start()只在有使用error_reporting设置下正常工作:

error_reporting(E_ALL); 
ini_set('display_errors', 1); 

在这种情况下,输出是“OK”,但是如果我删除error_reporting部分输出是“OKtest”。

问题是,我不能在生产网站上留下错误报告,我无法弄清楚为什么会发生这种情况。

也许需要更多的信息?

更新:预期的行为:sctipt发送状态200和身体响应 - “确定”,关闭连接,并开始做一些内部的东西。

+0

你是否已经检查过你的错误日志时'error_reporting'启用? –

+0

不幸的是,我没有远程服务器上的日志访问 – Alexander

+0

我不知道为什么你期望连接关闭和'测试'不输出。您的代码中没有任何内容说“关闭连接并继续执行其他操作”。 – deceze

下面的代码工作没有error_reporting

<?php 
    ob_start(); 
    echo 'OK'; // send the OK response 
    header('Connection: close'); 
    header('Content-Type: text/html; charset=utf-8'); 
    header('Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0'); 
    header("Content-Encoding: none"); 
    header('Content-Length: '.ob_get_length()); 

    echo 'test'; 
    // some further procesiing 

    exit; 
?> 

我有你最后的回声之前移除了这个,

ob_end_flush(); 
ob_flush(); 
flush(); 
+0

我恐怕没有按预期工作。我认为这个问题可能与服务器环境有关,因为我在本地机器上没有问题。但还是谢谢! – Alexander

+0

很高兴帮助:) –