本文介绍了PHP 和轮换代理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你们中有人尝试过使用轮换代理吗?这实施起来有多容易?它运作良好吗?请你的经验

Has anyone of you tried using rotating proxies? How easy is this to implement? Does it work well? Your experience please

PS:我看到类似how to让 php 脚本使用代理列表" 收集了很多缺点.你能在输入 -1 之前解释一下吗?

PS: i see questions like "how to make php script use a list of proxies" gather a lot of minuses. Can you explain this before putting -1?

推荐答案

------ 2017 年 3 月 4 日更新-------

我去过那里,发现最好的解决方案是:

I've been there and found that the best solution was:

如果您没有专用服务器,或者至少没有 vps 和一点耐心,请不要费心阅读帖子的其余部分...

1 - 从源代码安装 Squid 3.2(检查下面的注释)
2 - 将 20 个左右的 ip 列表添加到 squid.conf(每月费用约为 25 美元)
3 - 使用新功能 ACLrandom 来旋转传出 ip.

1 - Install Squid 3.2 from source (check notes below)
2 - Add a list of 20 or so ip's to squid.conf (costs about 25$ month)
3 - Use the the new feature ACLrandom to rotate the outgoing ip.

这样,你不需要在你的 php 脚本上轮换 ip 列表,相反,你将连接到同一个 ip(例如:192.168.1.1:3129)但是可见的传出 ip (tcp_outgoing_address) 将根据随机设置轮换每个请求.

This way, you don't need to rotate the list of ip's on your php script, instead, you'll be connecting to the same ip (ex: 192.168.1.1:3129) but the visible outgoing ip (tcp_outgoing_address) will rotate on every request based on the random settings .

您需要使用 '-enable-http-violations' 编译 squid 3.2 以使其成为精英匿名代理.

You'll need to compile squid 3.2 with '-enable-http-violations' in order to make it an elite anonymous proxy.

分步安装:

yum -y groupinstall 'Development Tools'
yum -y install openssl-devel
wget http://www.squid-cache.org/Versions/v3/3.2/squid-3.2.13.tar.gz
tar -xvf squid-3.2.13.tar.gz
cd squid-3.2.13
./configure -prefix=/squid32 '--enable-removal-policies=heap,lru' '--enable-ssl' '--with-openssl' '--enable-linux-netfilter' '--with-pthreads' '--enable-ntlm-auth-helpers=SMB,fakeauth' '--enable-external-acl-helpers=ip_user,ldap_group,unix_group,wbinfo_group' '--enable-auth-basic' '--enable-auth-digest' '--enable-auth-negotiate' '--enable-auth-ntlm' '--with-winbind-auth-challenge' '--enable-useragent-log' '--enable-referer-log' '--disable-dependency-tracking' '--enable-cachemgr-hostname=localhost' '--enable-underscores' '--enable-build-info' '--enable-cache-digests' '--enable-ident-lookups' '--enable-follow-x-forwarded-for' '--enable-wccpv2' '--enable-fd-config' '--with-maxfd=16384' '-enable-http-violations'
make
make install

squid.conf 示例(在本例中位于/squid32/etc/squid.conf):

#this will be the ip and port where squid will run
http_port 5.5.5.5:33333 # change this ip and port ...

#Extra parameters on squid.conf to make **an elite proxy**

request_header_access Allow allow all
request_header_access Authorization allow all
request_header_access WWW-Authenticate allow all
request_header_access Proxy-Authorization allow all
request_header_access Proxy-Authenticate allow all
request_header_access Cache-Control allow all
request_header_access Content-Encoding allow all
request_header_access Content-Length allow all
request_header_access Content-Type allow all
request_header_access Date allow all
request_header_access Expires allow all
request_header_access Host allow all
request_header_access If-Modified-Since allow all
request_header_access Last-Modified allow all
request_header_access Location allow all
request_header_access Pragma allow all
request_header_access Accept allow all
request_header_access Accept-Charset allow all
request_header_access Accept-Encoding allow all
request_header_access Accept-Language allow all
request_header_access Content-Language allow all
request_header_access Mime-Version allow all
request_header_access Retry-After allow all
request_header_access Title allow all
request_header_access Connection allow all
request_header_access Proxy-Connection allow all
request_header_access User-Agent allow all
request_header_access Cookie allow all
request_header_access All deny all

via off
forwarded_for off
follow_x_forwarded_for deny all

acl vinte1 random 1/5
acl vinte2 random 1/5
acl vinte3 random 1/5
acl vinte4 random 1/5
acl vinte5 random 1/5

tcp_outgoing_address 1.1.1.1 vinte1 # fake ip's , replace with yours
tcp_outgoing_address 1.1.1.2 vinte2
tcp_outgoing_address 1.1.1.3 vinte3
tcp_outgoing_address 1.1.1.4 vinte4
tcp_outgoing_address 1.1.1.5 vinte5

tcp_outgoing_address 1.1.1.6 # this will be the default tcp outgoing address

使用 squid 代理的 PHP CURL 请求示例:

$proxy = "1.1.1.1:33333";
$useragent="Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.1) Gecko/20061204 Firefox/2.0.0.1";
$url = "https://api.ipify.org/";

$ch = curl_init();
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT,15);
curl_setopt($ch, CURLOPT_HTTP_VERSION,'CURL_HTTP_VERSION_1_1' );
curl_setopt($ch, CURLOPT_HTTPPROXYTUNNEL, 1);
curl_setopt($ch, CURLOPT_PROXY, $proxy);
curl_setopt($ch, CURLOPT_PROXYUSERPWD,'USER:PASS');
curl_setopt($ch, CURLOPT_USERAGENT,$useragent);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION,1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER,0);
$result=curl_exec ($ch);
curl_close ($ch);
echo $result

有用的链接:
Squid 3.2 来源:http://www.squid-cache.org/Versions/v3/3.2/squid-3.2.13.tar.gz
Rotating_three_IPs:http://wiki.squid-cache.org/ConfigExamples/Strange/RotatingIPs#Example:_Rotating_three_IPs_based_on_time_of_day
AclRandom:http://wiki.squid-cache.org/Features/AclRandom
在 CentOS 5.3 上安装 Squid 3.2 - http://www.guldmyr.com/blog/installing-squid-3-2-on-centos-5-3/
为 Squid 添加密码:如何使用基本的用户名和密码认证设置squid Proxy?

我发现这是轮换代理的最可靠和最安全的方式,因为您不依赖第三方代理提供商,而且您的信息(密码、数据等)会更安全.一开始可能听起来有点困难,但它会在您花费的每一秒都得到回报,GL :)

I've found this to be the most reliable and secure way to rotate proxies because you don't rely on third party proxy providers and your information (passwords, data, etc) will be safer.It may sound a little difficult to setup at first but it will pay off every second you've spent, GL :)

这篇关于PHP 和轮换代理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-05 07:22