File in PHP

Source: Internet
Author: User
Tags curl header query domain name

This article shares some of the comparisons in PHP about the performance efficiencies of file_get_contents in curl. The content of the article from the network, if there is not the correct place, can be timely message added correction.

(1) Fopen/file_get_contents every time the data in the remote URL is requested to do the DNS query again, and the DNS information is not cached. 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) Fopen/file_get_contents when HTTP is requested, the use of Http_fopen_wrapper, will not keeplive. and curl can. This makes curl more efficient when multiple links are requested more than once. (Set header header should be OK)

(3) The 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. The 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. Fopen/file_get_contents can only obtain data using GET.

(5) fopen/file_get_contents cannot download binary files correctly.

(6) Fopen/file_get_contents cannot handle SSL requests properly.

(7) Curl can use multithreading.

(8) When using file_get_contents, if there is a problem with the network, it is easy to accumulate some process here.

(9) If you want to make a continuous connection, request multiple pages more than once. Then file_get_contents will go wrong. The contents may also be incorrect. So when doing some similar collection work, using curl as a substitute is a relatively correct choice.

Articles that you may be interested in

    • Summary of methods for using Curl post submission data and get access to Web page data in PHP
    • Use PHP function memory_get_usage to get current PHP memory consumption to achieve program performance optimization
    • How to troubleshoot PHP run appears call to undefined function Curl_init error
    • PHP prompts call to undefined function curl_init () Error resolution
    • How PHP uses the filter function to verify mailboxes, URLs, and IP addresses
    • Usage of several keywords in PHP, $this, Static, final, const, self, etc.
    • The difference and usage of return and exit, break and Contiue in PHP
    • Usage and difference of echo,print,print_r,var_export,var_dump in PHP


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.