Php 漏斗回音到输出文件中

Php 漏斗回音到输出文件中,php,Php,我正在异步发布到一个PHP文件,该文件反映了一些关键内容。我想将其所有输出写入日志文件。最简单的方法是什么?我会使用一个简单的包装器,比如。您只需包含该文件、实例化Logger类并设置路径。您需要在每次回显之后/之前执行日志记录操作。 <?php // Before you have any output! ob_start(); // All of your other code, echos, etc. // Sends the Output Buffer, also captur

我正在异步发布到一个PHP文件,该文件反映了一些关键内容。我想将其所有输出写入日志文件。最简单的方法是什么?

我会使用一个简单的包装器,比如。您只需包含该文件、实例化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 );
?>

我从一个网页发布表单数据,表单将发布到有问题的外部PHP文件,并且不会显示/转到该文件。