Log the request to log, in order to facilitate subsequent troubleshooting, in PHP to call a method, the implementation of the curl string can be recorded to facilitate the replication request.
<?php/** * author:xishizhaohua@qq.com * DATE:2015/11/2 * */function Getcurlcommand () {try {if (php_sapi_n Ame () = = ' Error cli ') {throw new Exception ("CLI"); } $curlCommand = ' curl '; $postData = $getData = "; if ($_get) {$gets = Http_build_query ($_get); $getData. = Strpos ($curlCommand, '? ')? ' & '. $gets: '? '. $gets; } if ($_server[' request_method ' = = ' POST ') {$posts = Http_build_query ($_post); $postData = '-d '. $posts. '"'; } $path = Isset ($_server[' script_name ')? $_server[' script_name ': $_server[' php_self ']; $curlCommand. = ' "'." http://{$_server[' Http_host '} ". $path. $getData. '"'; if ($postData) {$curlCommand. = $postData; } $headers = Array (); if (function_exists (' getallheaders ')) {$headers = Getallheaders (); } else {foreach ($_server as $name = = $value{if (substr ($name, 0, 5) = = ' Http_ ') {$headers [Str_replace (', '-', Ucwords (Strtolo Wer (Str_replace (' _ ', ' ', substr ($name, 5)))])] = $value; }}} foreach ($headers as $key + $value) {if ($key = = ' accept-encoding ') $value = Str_replace (' gzip, ', ', $value); $curlCommand. = '-h '. $key. ':' . $value. '"'; } return $curlCommand; } catch (Exception $e) {return $e->getmessage (); }}echo Getcurlcommand ();
eg
Curl "HTTP://LOCALHOST/OTHER/SERVERINFO.PHP?DD=DDD"-H "host:localhost"-H "connection:keep-alive"-H "Cache-control: Max-age=0 "-H" accept:text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8 "- H" user-agent:mozilla/5.0 (Windows NT 6.1; WOW64) applewebkit/537.36 (khtml, like Gecko) chrome/43.0.2357.132 safari/537.36 "- H" dnt:1 "-H" accept-encoding: Deflate, SDCH "-H" accept-language:zh-cn,zh;q=0.8,en;q=0.6 "-H" cookie:name=shikiliu; Email=xishizhaohua%40qq.com "
Related articles:
To view the request response time method using the Curl command
Server-side PHP Build Curl command line
Linux System Curl Command