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();//设置你需要抓取的URLcurl_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:functioncurl_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