File_get_content, curl, and fopen are most efficient.

Source: Internet
Author: User

Although all the three functions read resources, their respective application scenarios are different.

Curl is mostly used to capture web pages on the Internet, fopen is mostly used to read files, while file_get_contents is mostly used to obtain static page content.

1. fopen/file_get_contents each request will re-query the DNS and will not cache the DNS information. However, curl automatically caches DNS information. Only one DNS query is required for a webpage or image request under the same domain name. This greatly reduces the number of DNS queries. Therefore, curl performance is much better than fopen/file_get_contents.

2. When requesting HTTP, fopen/file_get_contents uses http_fopen_wrapper instead of keeplive. But curl does. In this way, curl is more efficient when multiple links are requested.

3. Curl can simulate multiple requests, such as post data and form submission. You can customize the requests as needed. Fopen/file_get_contents can only get data.

File_get_content, curl, and fopen are most efficient.

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.