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?
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
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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.