Search code examples
curltimeoutlibcurlphp-7

How to set a minimum timeout for curl(like libcurl 7.29) in PHP7


To guarantee the development environment can respond successfully, I would like to set a minimum timeout value for the curl response to return, like 300ms, even when the timeout is set to 50ms in the code to be deployed to production environment.

  1. Is there a way to make this work?
  2. Or are there any other alternatives to realize this? I just want the dev not to time-out due to the low performance of the test/dev machine.

Environment:

CentOS Linux release 7.2.1511 (Core)
$ curl -V
curl 7.29.0 (x86_64-redhat-linux-gnu) libcurl/7.29.0 NSS/3.44 zlib/1.2.7 libidn/1.28 libssh2/1.8.0

Solution

  • curl only has a timeout, there's no "minimum" or "maximum" timeout. If you set a timeout to curl, that is what goes.

    Technically speaking, there's both a connect timeout that only affects the "connection phase" and there's a global timeout that goes for the entire transfer, but you can only set either to a value or not set it.

    If a timeout is set in code somewhere that uses curl or libcurl, there's no way for anyone on the outside to forcibly change that timeout to a higher value, using standard curl mechanisms.