Home > Backend Development > PHP Tutorial > Comparison of performance efficiency between file_get_contents and curl in PHP_PHP Tutorial

Comparison of performance efficiency between file_get_contents and curl in PHP_PHP Tutorial

WBOY
Release: 2016-07-13 10:22:40
Original
1415 people have browsed it

Comparison of the performance efficiency of file_get_contents and curl in PHP

This article shares some comparisons of the performance efficiency of file_get_contents and curl in PHP. The content of the article is compiled from the Internet. If there is any inaccuracy, you can leave a message in time to make corrections.

(1) fopen/file_get_contents will re-do the DNS query every time the data in the remote URL is requested, and does not cache the DNS information. But CURL will automatically cache DNS information. Requests for web pages or images under the same domain name only require one DNS query. This greatly reduces the number of DNS queries. So the performance of CURL is much better than fopen/file_get_contents.

(2) When fopen/file_get_contents requests HTTP, it uses http_fopen_wrapper and does not keeplive. But curl can. In this way, curl will be more efficient when requesting multiple links multiple times. (It should be possible to set the header)

(3) The fopen/file_get_contents function will be affected by the allow_url_open option configuration in the php.ini file. If the configuration is turned off, this function will be disabled. 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 requests according to their own needs. And fopen/file_get_contents can only use the get method to obtain data.

(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 multi-threading.

(8) If there is a network problem when using file_get_contents, it is easy to accumulate some processes here.

(9) If you want to make a continuous connection, request multiple pages multiple times. Then file_get_contents will have problems. The obtained content may also be incorrect. Therefore, when doing some similar collection work, using curl as a replacement is a more correct choice.

Articles you may be interested in

  • A summary of how to submit data using curl’s post and how to get web page data using get in PHP
  • Using PHP functions memory_get_usage obtains the current PHP memory consumption to optimize program performance
  • How to solve the error of Call to undefined function curl_init when running PHP
  • Solution to the error of Call to undefined function curl_init() in php
  • The difference and usage of return and exit, break and contiue in PHP
  • Usage of several keywords such as $this, static, final, const, self and so on in php
  • php How to use filter function to verify email, url and ip address
  • The idea and implementation method of generating short URL in PHP

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/846810.htmlTechArticleComparison of file_get_contents and curl performance efficiency in PHP This article shares some comparisons of file_get_contents and curl performance efficiency in PHP . The content of the article is compiled from the Internet. If there are any errors...
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template