


php curl setting timeout example, phpcurl example_PHP tutorial
Jul 13, 2016 am 10:15 AMphp curl setting timeout example, phpcurl example
The example in this article describes the curl timeout setting method in PHP. Share it with everyone for your reference. The specific implementation method is as follows:
There are many ways to access HTTP, you can use curl, socket, file_get_contents() and other methods.
When accessing http, you need to consider the issue of timeout.
CURL access HTTP:
CURL is a commonly used lib library for accessing HTTP protocol interfaces. It has high performance and has some concurrency support functions.
curl_setopt($ch, opt) can set some timeout settings, mainly including:
① (Important) CURLOPT_TIMEOUT sets the maximum number of seconds that cURL is allowed to execute.
② (Important) CURLOPT_TIMEOUT_MS sets the maximum number of milliseconds that cURL is allowed to execute.
(Added in cURL 7.16.2. Available from PHP 5.2.3 onwards)
③ CURLOPT_CONNECTTIMEOUT is the time to wait before initiating a connection. If set to 0, it will wait indefinitely.
④ CURLOPT_CONNECTTIMEOUT_MS The time to wait for trying to connect, in milliseconds. If set to 0, wait infinitely. (Added in cURL 7.16.2. Available since PHP 5.2.3)
⑤ CURLOPT_DNS_CACHE_TIMEOUT sets the time to save DNS information in memory, the default is 120 seconds.
1. curl normal second-level timeout:
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_USERAGENT, $defined_vars['HTTP_USER_AGENT']);
2. Curl normal second-level timeout use:
Copy code
Copy code
I hope this article will be helpful to everyone’s PHP programming.
Several common PHP timeout handling methods

Hot Article

Hot tools Tags

Hot Article

Hot Article Tags

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian

How To Set Up Visual Studio Code (VS Code) for PHP Development
