PHP Curl capture Remote Page Content demo Code _php tutorial

Source: Internet
Author: User
There are many functions that can collect remote pages in PHP, such as file_get_contents (), fopen,file () These functions can collect remote server data, but to calculate performance curl most, he supports multithreading.

Cases

TD bgcolor= "#FFE7CE" height= "width=" 464 "> code as follows
copy code
$curlPost = ' a=1&b=2 ';//analog post data
$ch = Curl_ Init ();
curl_setopt ($ch, Curlopt_httpheader, Array (' x-forwarded-for:0.0.0.0 ', ' client-ip:0.0.0.0 '));//Construction IP
Curl_ Setopt ($ch, Curlopt_referer, "http://www.bkjia.com/"); Construct the route
curl_setopt ($ch, Curlopt_url, ' http://www.bkjia.com ');//page path to crawl
curl_setopt ($ch, Curlopt_ Returntransfer, 1);
curl_setopt ($ch, Curlopt_timeout, 30);
curl_setopt ($ch, Curlopt_postfields, $curlPost);//post value

$file _contents = curl_exec ($ch);//The contents of the crawl are placed in the variable
curl_close ($ch)

Another option is to use the file_get_contents () remote file fetch function to get the remote page content

Precautions

Curl () is highly efficient and supports multi-threading, but needs to turn on the next Curl extension. Here are the steps the Curl extension opens:

1, the PHP folder under the three files Php_curl.dll,libeay32.dll,ssleay32.dll copied to System32;

2, the php.ini (c:windows directory) in the; Extension=php_curl.dll in the semicolon removed;
3. Restart Apache or IIS.


http://www.bkjia.com/PHPjc/445611.html www.bkjia.com true http://www.bkjia.com/PHPjc/445611.html techarticle There are many functions that can collect remote pages in PHP, such as file_get_contents (), fopen,file () These functions can collect remote server data, but to calculate the performance curl most can, he supports ...

  • 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.