Reputation: 9325
I cannot curl localhost from php, but any other external host works fine.
From cmd I've tried "curl localhost" - it didn't work too, but ingnoring proxy for localhost "curl -v --noproxy localhost" - works.
What is equivalent for this in php?
Upvotes: 3
Views: 2557
Reputation: 195
I also faced same issue. I was working in a company which sits behind a proxy, so we need to add proxy to curl calls when making outbound calls. However, for locally hosted sites, the curl call was failing.
What worked for me is this one (CURLOPT_NOPROXY does not affect in PHP's the update part of the question where a link was provided):
curl_setopt($curl, CURLOPT_NOPROXY, 'your-sitename-on-localhost');
This will skip proxy when it matches a sitename in the URL.
Previously I was receiving 503, and now it is returning the correct 200 status code for the site on my localhost.
Upvotes: 2
Reputation: 409
You can try setting the proxy to an empty string:
curl_setopt($ch, CURLOPT_PROXY, '');
Another possibility is to add a proxy exception to your env var "no_proxy", but i'm not 100% sure if it affects PHP:
set no_proxy=127.0.0.1
Upvotes: 3