retrowaver/proxy-checker
Composer 安装命令:
composer require retrowaver/proxy-checker
包简介
Proxy Checker is a PHP library that allows you to quickly check a list of proxies.
README 文档
README
Proxy Checker is a PHP library that allows you to quickly check a list of proxies.
- fast (thanks to asynchronous requests)
- simple (PSR-7 based)
- supports many protocols
- customizable (full control over request / response checking)
Installation
composer require retrowaver/proxy-checker
How it works?
ProxyChecker constructor takes 2 mandatory arguments:
- PSR-7 Request
- object that implements
ResponseCheckerInterface
When checkProxies() is called, it attempts to send that request using every proxy, and then calls checkResponse() of provided ResponseCheckerInterface implementation, which ultimately decides whether proxy is valid or not.
Depending on how much control you want, you can use built-in ResponseCheckerBuilder for a quick start (see below) or make a custom class.
1. Basic usage
Step 1. Make proxy array
Make proxy array manually:
use Retrowaver\ProxyChecker\Entity\Proxy; $proxies = [ (new Proxy) ->setIp('127.0.0.1') ->setPort(1080) ->setProtocol('http'), (new Proxy) ->setIp('192.168.1.1') ->setPort(8080) ->setProtocol('http') ];
... or use built-in simple importer:
use Retrowaver\ProxyChecker\Import\SimpleImporter; $importer = new SimpleImporter; $lines = file('path-to-file-with-proxies.txt'); // ip:port format $proxies = $importer->import($lines, 'http');
Step 2. Prepare a request
Prepare a PSR-7 request that will be send using proxies.
use GuzzleHttp\Psr7\Request; $request = new Request('GET', 'http://example.com');
Step 3. Prepare ResponseChecker
You can use built-in ResponseCheckerBuilder:
use Retrowaver\ProxyChecker\ResponseChecker\ResponseCheckerBuilder; $responseChecker = (new ResponseCheckerBuilder) ->bodyContains('some string on target website') ;
or write a custom ResponseCheckerInterface implementation:
use Psr\Http\Message\ResponseInterface; use Retrowaver\ProxyChecker\Entity\ProxyInterface; class CustomResponseChecker implements ResponseCheckerInterface { public function checkResponse( ResponseInterface $response, ProxyInterface $proxy ): bool { if (...) { // proxy not valid return false; } // valid proxy return true; } }
$responseChecker = new CustomResponseChecker;
Step 4. Create ProxyChecker and check proxies
use Retrowaver\ProxyChecker\ProxyChecker; $proxyChecker = new ProxyChecker($request, $responseChecker); $validProxies = $proxyChecker->checkProxies($proxies);
2. Additional info
Options reference
ProxyChecker accepts optional parameters $options and $requestOptions:
$optionsconcurrency- max concurrent request (default 50)
$requestOptionsare Guzzle request options that are passed to Guzzle client while sending a request. Currently there's only one default value:'timeout' => 20
Supported protocols
PHP Proxy Checker should work with http, https, socks4, socks4a, socks5 and socks5h proxies (see https://curl.haxx.se/libcurl/c/CURLOPT_PROXY.html for descriptions).
retrowaver/proxy-checker 适用场景与选型建议
retrowaver/proxy-checker 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 22 次下载、GitHub Stars 达 2, 最近一次更新时间为 2020 年 02 月 05 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 retrowaver/proxy-checker 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 retrowaver/proxy-checker 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 22
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 2
- 点击次数: 4
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2020-02-05