The difference between Fopen,file_get_contents,curl functions in PHP

Source: Internet
Author: User
1.fopen/file_get_contents DNS queries are re-queried each time the request is made, and the DNS information is not cached. However, Curl automatically caches the DNS information. Requests for Web pages or images under the same domain name require only one DNS query. This greatly reduces the number of DNS queries. So curl has a much better performance than fopen/file_get_contents.

2.fopen/file_get_contents is using Http_fopen_wrapper when requesting HTTP, and will not keeplive. and curl can. This makes curl more efficient when multiple links are requested more than once.

The 3.fopen/file_get_contents function is affected by the configuration of the Allow_url_open option in the php.ini file. If the configuration is turned off, the function is invalidated. Curl is not affected by this configuration.

4.curl can simulate a variety of requests, such as post data, form submission, etc., users can customize the request according to their own needs. Instead, fopen/file_get_contents can only get data using the Get method.
File_get_contents gets a remote file when the result is present in a string Fiels function stores the array form

Overall

File_get_contents processing is often small, it feels good to use it. Nothing unusual. If your file is handled by a 1k+ person. Then your server CPU is waiting for a lift. So it is recommended that you use the Curl library when you write PHP code later.

Original address: http://www.jb51.net/article/57238.htm

The above describes the PHP Fopen,file_get_contents,curl function of the difference, including the aspects of the content, I hope that the PHP tutorial interested in a friend helpful.

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