{"id":19831,"date":"2020-02-06T22:13:43","date_gmt":"2020-02-06T14:13:43","guid":{"rendered":"http:\/\/4563.org\/?p=19831"},"modified":"2020-02-06T22:13:43","modified_gmt":"2020-02-06T14:13:43","slug":"web%e8%ae%bf%e9%97%ae-php-curl-%e5%87%bd%e6%95%b0%e4%b8%8d%e8%83%bd%e8%81%94%e7%bd%91","status":"publish","type":"post","link":"http:\/\/4563.org\/?p=19831","title":{"rendered":"WEB\u8bbf\u95ee php curl() \u51fd\u6570\u4e0d\u80fd\u8054\u7f51"},"content":{"rendered":"\n<p>  \t\t\t\t\t<strong>yisuo<\/strong>  \t\t\t\t\u5927\u4f6c\u6709\u8bdd\u8bf4 : \t<\/p>\n<h3>WEB\u8bbf\u95ee php curl() \u51fd\u6570\u4e0d\u80fd\u8054\u7f51<\/h3>\n<p>  \t\tWEB \u73af\u5883 UBUNTU + APACHE2 +php<\/p>\n<p>  apt install -y apache2 php libapache2-mod-php php-curl php-mbstring php-gd<br \/>  a2enmod php<br \/>  apachectl -k start<\/p>\n<p>  \u5728 root\u7528\u6237\u4e0b\u4f7f\u7528 php -f \/home\/www\/html\/test\/c.php \u4e00\u5207\u6b63\u5e38<\/p>\n<p>  \u800c\u5728 \u6d4f\u89c8\u5668\u4e2d\u7528 http:\/\/localhost\/test\/c.php \u8bbf\u95ee\uff0c\u8868\u73b0\u4e3aphp\u7684CURL \u4e0d\u80fd\u83b7\u53d6\u4efb\u4f55\u7f51\u7edc\u8d44\u6e90<\/p>\n<p>  DNS\u4e5f\u6ca1\u6709\u95ee\u9898<\/p>\n<p>  cat \/etc\/resolv.conf<br \/>  chmod 644 \/etc\/resolv.conf<\/p>\n<p>  \u4e0b\u9762\u8fd9\u662f\u6d4b\u8bd5\u4ee3\u7801 c.php<\/p>\n<p>  &lt;?php<br \/>  echo &#8216;&lt;pre&gt;&#8217;;<br \/>  echo &quot;=========file_get_contents()=========&lt;br&gt;&quot;;<br \/>  echo file_get_contents(&#8216;http:\/\/localhost&#8217;);<\/p>\n<p>  echo &quot;=========gethostbyname()=========&lt;br&gt;rn&quot;;<br \/>  var_dump();<\/p>\n<p>  echo &quot;=========curl()=========&lt;br&gt;rn&quot;;<br \/>  $ch = curl_init();<br \/>  curl_setopt($ch, CURLOPT_URL,&quot;http:\/\/www.baidu.com&quot; );<br \/>  curl_setopt($ch, CURLOPT_DNS_USE_GLOBAL_CACHE, true );<br \/>  if(curl_exec($ch) === false){<br \/>  &nbsp; &nbsp; echo &#8216;Curl error: &#8216; . curl_error($ch);<br \/>  }else{<br \/>  &nbsp; &nbsp; echo &quot;It&#8217;s all done&quot;;<br \/>  }<br \/>   echo &quot;&lt;br&gt;rn==================&lt;br&gt;&lt;br&gt;&lt;br&gt;rn&quot;;  \t\t\t\t<\/p>\n<p>  \t\t\t\t\t<strong>\u5927\u817f<\/strong>  \t\t\t\t\u5927\u4f6c\u6709\u8bdd\u8bf4 : \t<\/p>\n<h3><\/h3>\n<p>  \t\t\u786e\u8ba4\u4e0b \u5728 cli\u548chttp\u662f\u4e0d\u662f\u4e00\u4e2a\u7248\u672c<\/p>\n<p>  \t\t\t\t\t<strong>yisuo<\/strong>  \t\t\t\t\u5927\u4f6c\u6709\u8bdd\u8bf4 : \t<\/p>\n<h3><\/h3>\n<p>  \t\t\/usr\/bin\/php -v \u663e\u793a PHP 7.2.3-1ubuntu1 (cli)<\/p>\n<p>  http\u4e2d\u4f7f\u7528phpinfo()\u67e5\u770b\u5230 PHP Version 7.2.3-1ubuntu1\t\t\t\t<\/p>\n<p>  \t\t\t\t\t<strong>yisuo<\/strong>  \t\t\t\t\u5927\u4f6c\u6709\u8bdd\u8bf4 : \t<\/p>\n<h3><\/h3>\n<p>  \t\t\u5927\u817f \u5927\u4f6c\u6709\u8bdd\u8bf4 : 2020-2-6 21:58<br \/>  \u786e\u8ba4\u4e0b \u5728 cli\u548chttp\u662f\u4e0d\u662f\u4e00\u4e2a\u7248\u672c<\/p>\n<p> \u5e94\u8be5\u662f\u540c\u4e00\u4e2a\u7248\u672c\u5462\uff0c\t\t\t\t<\/p>\n<p>  \t\t\t\t\t<strong>\u9038\u7b19<\/strong>  \t\t\t\t\u5927\u4f6c\u6709\u8bdd\u8bf4 : \t<\/p>\n<h3><\/h3>\n<p>  \t\t\u62a5\u9519\u5462\uff1f\u622a\u56fe\u5462\uff1f\t\t\t  <\/p>\n","protected":false},"excerpt":{"rendered":"<p>yisuo \u5927\u4f6c\u6709\u8bdd\u8bf4 : WEB&hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[],"tags":[],"_links":{"self":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/19831"}],"collection":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=19831"}],"version-history":[{"count":0,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/19831\/revisions"}],"wp:attachment":[{"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=19831"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=19831"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=19831"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}