Home  >  Article  >  Backend Development  >  Introduction to the usage of php curl library

Introduction to the usage of php curl library

WBOY
WBOYOriginal
2016-07-25 08:53:31789browse
This article introduces the usage of the curl library in PHP. The curl library under PHP mainly has two requests and guzzle. Both of them are very complicated. Friends in need can refer to them.

The php curl library 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 the 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 the v3 version), and relies on symfony's eventemitter, which is depended on 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 was meaningless and resulted in both It is not forward compatible and inconsistent with other common PHP libraries. Now is the key point. Guzzle usually works well, but yesterday I discovered a problem. There was a remote URL and I had to go to Alipay to check the payment results. When calling this URL, guzzle will not succeed, but requests will. Regarding 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, and no timeout- is given. max sets the value, but due to inclusion, when you don't 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 the guzzle document clearly states that it is enabled. If Required, it needs to be closed manually. in accordance with: The default connect-timeout of curl is 300 seconds https://github.com/bagder/curl/blob/master/lib/connect.h 3.8 how do i tell curl to follow http redirects? http://curl.haxx.se/docs/faq.html



Statement:
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