File_get_content and Curl in PHP and fopen efficiency analysis _php Skills

Source: Internet
Author: User
Tags curl

Three functions, although they are all functions that read resources, differ in their application scenarios.

Curl is used for crawling between Web pages, fopen is used to read files, and file_get_contents is used to get static page content more.

1. Fopen/file_get_contents each request will redo the DNS query, does not cache DNS information. However, Curl will automatically cache DNS information. Requests for a Web page or picture under the same domain name require only a single DNS query. This greatly reduces the number of DNS queries. So curl performance is much better than fopen/file_get_contents.

2. When requesting HTTP, the fopen/file_get_contents uses Http_fopen_wrapper and does not keeplive. and curl can. This makes curl more efficient when multiple links are requested more than once.

3. Curl can simulate a variety of requests, such as post data, form submission, etc., users can customize the request according to their own needs. Fopen/file_get_contents can only obtain data using GET.

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.