Home >Backend Development >PHP Tutorial >cURL library under PHP
The cURL library under PHP mainly has two Requests and Guzzle, both of which are very complex.
Requests uses cURL first. If there is no cURL, fsockets will be automatically enabled unless you specify Transport manually.
Guzzle has rich log library support and log formats. It uses plug-in subscription to subscribe. From the code point of view, it uses an event mechanism and has higher quality.
It only supports cURL (at least only v3) and relies on Symfony's EventEmitter, which is relied upon by ReactPHP.
Recently (2014-03-28) I found that it was upgraded from v3.8.1 to v4.0.0rc. The Namespace was actually changed, the first two paragraphs were reduced to one paragraph, and the top-level Guzzle was also removed from the source code directory. It is meaningless. As a result, it is neither forward compatible nor inconsistent with other common PHP libraries.
Now is the key point. Guzzle usually works well, but yesterday I found a problem. There is a remote URL and I have to go to Alipay to check the payment results. When calling this URL, Guzzle will not succeed, but Requests will.
The following is about the cURL command. It has two timeouts, connect-timeout and timeout-max (the latter is usually called timeout in the program), of which the latter includes the former. The default connect-timeout of cURL is 300 seconds, no value is set for timeout-max, but due to inclusion, when you do not set timeout, it is at least 300 seconds.
For PHP’s fsockets, since there is a configuration item default_socket_timeout in php.ini, its default value is only 60 seconds.
In addition, cURL does not support http redirect by default and needs to pass the -L option (no parameters). However, based on the experience of using PHP and Python, many cURL libraries enable redirect by default. At least Guzzle's documentation clearly states that it is enabled. , close manually if necessary.
Based on:
curl’s default connect-timeout is 300 seconds