PHP Request Remote Link

Source: Internet
Author: User

PHP request remote links commonly used to parse the interface of other people, generally we will think of using file_get_contents this function, but the efficiency of the sub-function is relatively low, if a large range of use may cause page lag phenomenon, so the ideal way is to use curl, Let me briefly share the following:

One, curl GET request:

$url ‘127.0.0.1/test.php‘ ;//换成你要请求的url地址即可。 //初始化一个 cURL 对象 $ch = curl_init(); //设置你需要抓取的URL curl_setopt( $ch , CURLOPT_URL,  $url ); // 设置cURL 参数,要求结果保存到字符串中还是输出到屏幕上。 curl_setopt( $ch , CURLOPT_RETURNTRANSFER, 1); //是否获得跳转后的页面 curl_setopt( $ch , CURLOPT_FOLLOWLOCATION, 1); $data = curl_exec( $ch ); curl_close( $ch ); echo $data ;Two, Curl POST request: function curl_post( $url $arr_data ){     $post_data = http_build_query( $url_data );     $ch = curl_init();      curl_setopt( $ch , CURLOPT_URL,  $url );      curl_setopt( $ch , CURLOPT_RETURNTRANSFER, 1);      curl_setopt( $ch , CURLOPT_POST, 1);      curl_setopt( $ch ,  CURLOPT_POSTFLELDS,  $post_data );      $data = curl_exec( $ch );      curl_close( $ch );      echo $data ; } $arr_post array (      ‘name‘ => ‘test_name‘ ,      ‘age‘ => 1 ); curl_post( "http://www.explame.com/" $arr_post );Curl is also often used when collecting web data.

PHP Request Remote Link

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.