PHP CURL service calls a third-party interface to set the timeout period

PHP CURL service calls a third-party interface to set the timeout period

#If you do not set the connection timeout time and waiting timeout time

PHP uses curl to develop the habit of setting timeout time, most of the online PHP Curl code is not set

  • Reptile business: will block the process, especially when accessing foreign resources
  • Business interface: Affect the user experience, need to set the timeout time according to the business, and record the error log for feedback to the relevant personnel after the specified time

#Suggest

  1. Develop good habits
  2. If you use PHP to generate CURL extensions, it is best to package a composer yourself
  3. Use third-party libraries, such as guzzlehttp/guzzle, most authors will set a default time

#PHP CURL timeout parameter

//Connection timeout
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10);
//Wait for response timeout, choose one of two
curl_setopt($ch, CURLOPT_TIMEOUT, 10); //second level
curl_setopt($ch, CURLOPT_TIMEOUT_MS, 10);//millisecond level

#Support Author

coffee


Did you enjoyed the article ?
Subscribe to the newsletter 👨‍💻

Be the first to know when I write something new! If you don't like emails, you can follow me on GitHub.