2016-03-01 62 views
0

我有一個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

回答

0

下面的代碼工作沒有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

很高興幫助:) –