Comparison of performance efficiency of file_get_contents to curl in PHP
This article shares some of the comparisons in PHP about the performance efficiency of file_get_contents in curl. The content of the article is organized from the network, if there is incorrect place, can be timely message to add correction.
(1) Fopen/file_get_contents each time the data in the remote URL is requested, the DNS query is re-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 header should be set)
(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. 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.
(5) fopen/file_get_contents cannot download binary files correctly.
(6) Fopen/file_get_contents cannot handle SSL requests correctly.
(7) Curl can take advantage of multithreading.
(8) When using file_get_contents, if the network is having problems, it is easy to accumulate some process here.
(9) If you want to make a persistent connection, request multiple pages more than once. Then file_get_contents will go wrong. The content obtained may also be incorrect. So when doing some similar collection work, using curl instead is a more correct choice.
Articles you may be interested in
- How to use Curl's post submission data in PHP and get a summary of how to get Web page data
- Use PHP function memory_get_usage to get the current PHP memory consumption to achieve program performance optimization
- How to troubleshoot PHP run with a call to undefined function Curl_init error
- PHP tips for solutions to undefined function curl_init () errors
- The difference and usage of return and exit, break and Contiue in PHP
- PHP $this, Static, final, const, self, and several other key words to use
- Php method for verifying mailboxes, URLs, and IP addresses using the filter function
- The idea and implementation method of PHP generating short URLs
http://www.bkjia.com/PHPjc/846810.html www.bkjia.com true http://www.bkjia.com/PHPjc/846810.html techarticle Comparison of file_get_contents performance efficiency in PHP This article shares some of the comparisons in PHP about the performance efficiency of file_get_contents in curl. The content of the article is organized from the network, if there is an incorrect ...