0
我異步地發佈到一個PHP文件,它迴應了幾個關鍵的東西。我想將它的所有輸出寫入日誌文件。最簡單的方法是什麼?將回聲傳送到輸出文件
我異步地發佈到一個PHP文件,它迴應了幾個關鍵的東西。我想將它的所有輸出寫入日誌文件。最簡單的方法是什麼?將回聲傳送到輸出文件
我會使用一個簡單的包裝,如http://www.redips.net/php/write-to-log-file/。您只需包含該文件,實例化Logger類並設置路徑。您需要在每個回聲之後/之前執行日誌記錄操作。
<?php
// Before you have any output!
ob_start();
// All of your other code, echos, etc.
// Sends the Output Buffer, also captures it in the $output variables
$output = ob_get_flush();
// Some extra info for the Logfile, so you know when and who saw it
$logPrefix = "\n\n".
"Time: ".date('Y-m-d H:i:s')."\n".
"IP: ".$_SERVER['REMOTE_ADDR']."\n\n";
// Write the data to the Logfile, and append it to the end (if file already exists)
file_put_contents('yourLogfile.txt' , $logPrefix.$output , FILE_APPEND);
?>
你從哪裏發佈? – 2011-05-07 20:37:25
我正在從網頁發佈表單數據,表單將發佈到外部PHP文件,並且不會顯示/轉到該表單。 – AKor 2011-05-07 20:40:11