Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/file/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何在响应客户端之前将整个http响应保存到服务器端的日志文件中_Php_File - Fatal编程技术网

Php 如何在响应客户端之前将整个http响应保存到服务器端的日志文件中

Php 如何在响应客户端之前将整个http响应保存到服务器端的日志文件中,php,file,Php,File,我想知道是否有可能在发送响应之前,在一些php脚本的末尾保存服务器端的整个http响应?如果我能以十六进制格式保存响应就更好了?或者我可以在apache日志中看到它吗 非常感谢 编辑: function shutDownFunction() { $error = error_get_last(); if ( !empty($error) ) { header('HTTP/1.0 500' .$error );

我想知道是否有可能在发送响应之前,在一些php脚本的末尾保存服务器端的整个http响应?如果我能以十六进制格式保存响应就更好了?或者我可以在apache日志中看到它吗

非常感谢

编辑:

      function shutDownFunction() {


        $error = error_get_last();

        if ( !empty($error) ) {

            header('HTTP/1.0  500' .$error );
        } else { 
           header('HTTP/1.0 200');
           return '<html> <body> ... </body></html>';
        }



    }

register_shutdown_function('shutdownFunction');

try { 

 $data = file_get_contents("php://input");

  //do some work here 

    } catch (Exception $e) {

        header('HTTP/1.0 503'); 

        die;
    }

在脚本的结尾处,请输入:

ob_start();
把这个放在脚本的末尾

$output = ob_get_clean();
echo $output;
file_put_contents(time().'output.txt', $output);

在脚本的结尾处,请输入:

ob_start();
把这个放在脚本的末尾

$output = ob_get_clean();
echo $output;
file_put_contents(time().'output.txt', $output);

仅仅用PHP并不容易,最好用apache日志。我确信会有一个选项来记录所有的输出,单用PHP并不容易,最好用apache日志。我肯定会有一个选项来记录所有outputs@Phoenix,我已经编辑了这个问题。我的意思是,你为什么需要记录这些信息?你到底想解决什么问题?@Phoenix,我已经编辑了这个问题。我的意思是,你为什么需要记录这些信息?你到底想解决什么问题?