Forcing cURL to use DNS though SOCK5 proxy

I recently had to code a REST call to a service I could only access behind a SOCK5 proxy.  Unfortunately, the hostname of the service wasn’t publicly resolvable so the DNS had to be resolved on the other side of the proxy.  Whilst this is pobbible in cURL itself by using the CURLOPT_PROXYTYPE option and setting it to CURLPROXY_SOCKS5_HOSTNAME or by using the flag –socks5-hostname – the constant isn’t available within PHP.  This feature was requested in however hasn’t yet been implemented.  This can simply be worked around by setting the proxy type to 7.  The code below shows an example of doing this using the Httpful library, however if you were using curl natively you’d just use curl_setopt()


$r = HttpfulRequest::post($url)
->addOnCurlOption(CURLOPT_PROXY, 'localhost:8080')
->addOnCurlOption(CURLOPT_PROXYTYPE, 7)

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.