记录请求到log,为了方便后续排查问题,在php里调用一个方法,实现将curl串记录下来即可方便复现请求。
<?php
/**
 * author: xishizhaohua@qq.com
 * date: 2015/11/2
 * 
 */
function getcurlcommand()
{
    try {
        if (php_sapi_name() == '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(strtolower(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”
相关文章:
使用curl命令查看请求响应时间方法
服务器端php生成curl命令行
linux系统curl命令
   
 
   