CURLOPT_NOPROXY does not affect in PHP

2019-06-21 13:21发布

I have http_proxy settings in my /etc/environment on my Ubuntu machine. I have defined CURLOPT_NOPROXY as 10177 and then do

$curl = curl_init('http://127.0.0.1:4444/wd/hub');
curl_setopt($curl, CURLOPT_NOPROXY, '127.0.0.1'); // or '*'
// ... set others params and options ...
curl_exec($curl);

But this does not affect my script and I receive proxy error message instead of WebDriver response. At the same time using curl --noproxy 127.0.0.1 http://127.0.0.1:4444/wd/hub from command line works well.

Additional env info:

curl --version
curl 7.22.0 (x86_64-pc-linux-gnu) 
libcurl/7.22.0 OpenSSL/1.0.1 zlib/1.2.3.4 
libidn/1.23 librtmp/2.3 
Protocols: dict file ftp ftps gopher http https imap imaps ldap pop3 pop3s rtmp rtsp smtp smtps telnet tftp 
Features: GSS-Negotiate IDN IPv6 Largefile NTLM NTLM_WB SSL libz TLS-SRP 

PHP version is 5.3.10.

How can I set up noproxy option from my PHP script?

UPDATED: Looks like it should work https://bugs.php.net/bug.php?id=53543 in PHP.

标签: php curl proxy
3条回答
The star\"
2楼-- · 2019-06-21 13:25

According to PHP's Manual, you should set CURLOPT_HTTPPROXYTUNNEL to false:

curl_setopt($ch, CURLOPT_HTTPPROXYTUNNEL, false);
查看更多
beautiful°
3楼-- · 2019-06-21 13:29

I also had a problem with curl using a proxy only in PHP curl calls. I eventually found that SUSE specifically SLES 11 had some proxy values set. Changing those proxy values fixed issues in linux but I had to restart the entire server not just apache for the changes to take affect in PHP. I used YAST to change the proxy values on the server.

查看更多
对你真心纯属浪费
4楼-- · 2019-06-21 13:33

It happened with me so i set the proxy to empty string and it worked

curl_setopt($ch, CURLOPT_PROXY, '');
查看更多
登录 后发表回答