Home > Article > Backend Development > Does PHP CURL business need to set a timeout when calling third-party interfaces?
php When using curl, you need to develop the habit of setting the timeout. Most of the online PHP Curl codes do not set it
1. Develop good habits
2. If you use PHP native CURL extension, it is best to encapsulate one yourself composer
3. When using a third-party library, such as guzzlehttp/guzzle
, most authors will set a default time
//连接超时时间 curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10); //等待响应超时时间二选一 curl_setopt($ch, CURLOPT_TIMEOUT, 10); //秒级 curl_setopt($ch, CURLOPT_TIMEOUT_MS, 10);//毫秒级
[Recommended learning: "PHP Video Tutorial"]
The above is the detailed content of Does PHP CURL business need to set a timeout when calling third-party interfaces?. For more information, please follow other related articles on the PHP Chinese website!