Sometimes, we want to set curl’s timeout in PHP.
In this article, we’ll look at how to set curl’s timeout in PHP.
How to set curl’s timeout in PHP?
To set curl’s timeout in PHP, we can set the CURLOPT_CONNECTTIMEOUT
and CURLOPT_TIMEOUT
options.
For instance, we write
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 0);
curl_setopt($ch, CURLOPT_TIMEOUT, 400);
to set the CURLOPT_CONNECTTIMEOUT
option with curl_setopt
to set the connect timeout to 0, which makes the timeout indefinite.
And we call curl_setopt
again to set CURLOPT_TIMEOUT
to 400 seconds.
Then we write
set_time_limit(0);
to call set_time_limit
with 0 to make the max execution time of the PHP script indefinite.
Conclusion
To set curl’s timeout in PHP, we can set the CURLOPT_CONNECTTIMEOUT
and CURLOPT_TIMEOUT
options.