Tag Archives: php curl

PHP’s cURL and how to use CURLPROXY_SOCKS5_HOSTNAME

So, you’re running a proxy (say, something like TOR) on your locallopback.. but you keep getting this error (must have VERBOSE set to true to catch it):

* Hostname was NOT found in DNS cache
* Can’t complete SOCKS5 connection to 0.0.0.0:0. (2)
* Closing connection 0

Your code looks simple enough.. but it doesn’t work:

A little research later you find that the PROPER SOCKS5 protocol is SOCKS5H (hostname), so you use the proper flag..

[…]
curl_setopt($ch, CURLOPT_PROXYTYPE, CURLPROXY_SOCKS5_HOSTNAME);
[…]

only to get told that TOR doesn’t want to be used as an HTTP proxy (what’s the deal)?


It appears you have configured your web browser to use Tor as an HTTP proxy.
This is not correct: Tor is a SOCKS proxy, not an HTTP proxy.
Please configure your client accordingly.

Have not fear script-kiddies.. even though PHP as of 5.5.x does not seem to include this CRITICAL cURL FLAG, you can reference it directly with the integer value of 7. So… if you change your code to this… you’re as golden as the proverbial goose!

curl_setopt($ch, CURLOPT_PROXYTYPE, 7); // 7 = CURLPROXY_SOCKS5_HOSTNAME

So… now you know!

find my article helpful? print some coupons!