akim-bow / guzzle-proxy-handler
GuzzleHTTP 的中间件,允许轻松使用多个代理配置
v0.2.1
2021-11-30 03:13 UTC
Requires
- guzzlehttp/guzzle: ^7.0
- nesbot/carbon: ^2.54
Requires (Dev)
- phpunit/phpunit: ^9.5
README
这个库被创建用来简化通过 guzzle-http 库使用代理
composer require akim-bow/guzzle-proxy-handler
示例
示例 1
// You can use this function to load proxies from config or create proxy array manually $proxyObjects = \ProxyHandler\ProxyManager::getProxyObjects('path to config'); $sps = new SequenceProxyStrategy($proxyObjects); $client = \ProxyHandler\ProxyManager::createProxyClient($sps, [ 'timeout' => 5, ]); $client->get('https://google.com'); $client->get('https://google.com'); $client->get('https://google.com'); echo "Every request was send with configured proxy";
策略
序列策略
这个默认策略会循环遍历你的代理,并依次使用它们。
权重策略
这个策略可以与权重类一起使用,为请求计算权重。不能用于异步请求。