我想知道是否可以在发送响应之前在某些 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;
}
我想保存整个响应,包括标题,我不知道,例如:
GET /tutorials/other/top-20-mysql-best-practices/ HTTP/1.1
Host: net.tutsplus.com
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.1.5) Gecko/20091102 Firefox/3.5.5 (.NET CLR 3.5.30729)
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: en-us,en;q=0.5
Accept-Encoding: gzip,deflate
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
Keep-Alive: 300
Connection: keep-alive
Cookie: PHPSESSID=r2t5uvjq435r4q7ib3vtdjq120
Pragma: no-cache
Cache-Control: no-cache