1. fopen /file_get_contents will re-do the DNS query for each request 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.fopen /file_get_contents When requesting HTTP, http_fopen_wrapper is used and will not keeplive. But curl can. In this way, curl will be more efficient when requesting multiple links multiple times.
3.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.
When file_get_contents obtains remote files, the results will be stored in a string. The fiels function will store them in an array form
Overall
When file_get_contents processing is frequent and small, it feels good to use it. Nothing unusual. If your file is processed by 1k people. Then your server CPU is waiting to increase. Therefore, I recommend that you and yourself use the curl library when writing PHP code in the future.
Original address: http://www.jb51.net/article/57238.htm