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