Server-side PHP Build Curl command line

Source: Internet
Author: User
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

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.