Return CURLOPT_INTERFACE to its default behavior in PHP

If you look at the CURLOPT_INTERFACE manual you will find that setting it to NULL to will tell cURL to use whatever the TCP stack finds suitable (default behavior), however that isn’t the case in PHP.

If you set NULL on CURLOPT_INTERFACE using curl_setopt like this:

curl_setopt( $ch, CURLOPT_INTERFACE, null );

You will wind up with Error Code: 45 (Could not resolve host)

That’s because PHP does not support it. According to to curl-setopt manual:

CURLOPT_INTERFACE = The name of the outgoing network interface to use. This can be an interface name, an IP address or a host name.

CURLOPT_INTERFACE only accepts valid string in PHP. It does not accept NULL, array() or "" (empty string).


Set it to

curl_setopt( $ch, CURLOPT_INTERFACE, '' );

Now, cURL will use whatever the TCP stack finds suitable (default behavior).

Why ? – Read

All the credits goes to /u/ta22175 for giving me the solution.