2

Here is the code in question:

$ch = curl_init();
curl_setopt(CURLOPT_URL, 'https://api.ipify.org?format=json');
curl_setopt(CURLOPT_PROXY, 'ip:port');
curl_setopt(CURLOPT_PROXYUSERPWD, 'user:pass');
$result = curl_exec($ch);
echo curl_error($ch);

The proxy and proxyauth I'm using most definitely work. I've actually tried multiple proxies from various sources with and without auth, but every time I get a connection timeout when connecting to the proxy.

Is there a config setting preventing proxies from being used or something that I'm not aware of? Any help here will be greatly appreciated.

Branden
  • 237
  • 4
  • 13
  • try adding `curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);` – Ben Rowe Dec 03 '15 at 23:51
  • Thanks for the suggestion. I added that option, however I'm still getting the same timeout issue. – Branden Dec 03 '15 at 23:58
  • try running curl through the cli, instead of php to see if it's a problem with the server connecting to the proxy, or something within php. – Ben Rowe Dec 04 '15 at 00:09
  • Just ran the command through the command line, still getting a timeout. So it's definitely not PHP-specific.. in that case I'll have a chat with the server's support team. Thanks for helping me debug the issue. – Branden Dec 04 '15 at 00:19
  • 1
    Possible duplicate of [How to use CURL via a proxy?](http://stackoverflow.com/questions/5211887/how-to-use-curl-via-a-proxy) – miken32 Dec 04 '15 at 00:52

3 Answers3

3

You need to use CONNECT method for https urls :

curl_setopt($ch, CURLOPT_HTTPPROXYTUNNEL, 1);

But some proxies doesn't support this feature.

Yoann Kergall
  • 2,993
  • 5
  • 22
  • 23
1

I solved this issue and just wanted to update this question.

The problem was with the server configuration. Only the most common outbound ports were enabled, and I was using proxies with random ports across the whole spectrum. Enabling the ports that I needed (you could just have the restriction disabled altogether) fixed the issue.

So if you run into this same issue where you're timing out while trying to connect to a proxy, contact your support and ask about any restrictions on the outbound ports.

Branden
  • 237
  • 4
  • 13
0

Sounds like an HTTPS issue to me. Try:

curl_setopt($ch,CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch,CURLOPT_SSL_VERIFYHOST, false);

It might also just be a slow URL, so try:

curl_setopt($ch, CURLOPT_CONNECTTIMEOUT ,0); 
curl_setopt($ch, CURLOPT_TIMEOUT, 400);//max seconds to allow cURL functions to run

If there's any redirects involved, you can also try:

curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);

If that doesn't work, try testing more URLs and see if it's an https issue with every site you try, and whether you can recreate the same issue with http. Also check make sure you have PHP's error reporting enabled, and see if you're getting any errors or warnings. Try deliberately causing PHP to generate an error or warning to see if error reporting is working correctly.

Ultimater
  • 4,647
  • 2
  • 29
  • 43