tregor/proxyman
Composer 安装命令:
composer require tregor/proxyman
包简介
ProxyMan is OpenSource library for PHP, that makes work with proxies easy!
README 文档
README
ProxyMan is OpenSource library for PHP, that makes work with proxies easy!
It providing useful proxy manager, that contains any count of proxies, makes automatic connection test and provides easy to use proxy server information
Navigation
Requirements
This library is supported by PHP versions 5.4 or higher.
Installation
The preferred way to install this extension is through Composer.
To install PHP ErrorHandler library, simply:
$ composer require tregor/proxyman
You can also clone the complete repository with Git:
$ git clone https://github.com/tregor/proxyman.git
Quick Start and Usage
You can see more in example.php file.
<?php use tregor\ProxyMan\Exception\ProxyException; use tregor\ProxyMan\ProxyManager; //Adding proxy to manager ProxyManager::addProxyHTTP("127.0.0.1", "3128"); //Simple Curl request with proxy $ch = curl_init("https://www.google.com"); curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); try{ //Getting random proxy from Manager $proxy = ProxyManager::getRandomProxy(); }catch (ProxyException $e){ echo "Error occurred: ".$e->getMessage(); } //Setting Curl proxy type by Proxy method curl_setopt($ch, CURLOPT_PROXYTYPE, $proxy->getType()); //Setting Curl proxy host and port string by Proxy method curl_setopt($ch, CURLOPT_PROXY, $proxy->getHostPort()); if ($proxy->hasAuth()){ curl_setopt($ch, CURLOPT_PROXYAUTH, CURLAUTH_BASIC); //Setting Curl proxy username and password string by Proxy method curl_setopt($ch, CURLOPT_PROXYUSERPWD, $proxy->getUserPass()); } $response = curl_exec($ch); curl_close($ch); echo "<pre>".$response."</pre>";
Available Methods
Available methods in this library:
- Adding proxy:
This will add proxy to your proxy list. You must to chose method that coresponds your proxy type (HTTP, HTTPS, SOCKS4, SOCKS5).
ProxyManager::addProxyHTTP(string $host, string $port, string $username = "", string $password = "");
ProxyManager::addProxyHTTPS(string $host, string $port, string $username = "", string $password = "");
ProxyManager::addProxySOCKS4(string $host, string $port, string $username = "", string $password = "");
ProxyManager::addProxySOCKS5(string $host, string $port, string $username = "", string $password = "");
- Get random proxy
This will return one of your proxies, after it automatic test.
ProxyManager::getRandomProxy();
- Get all available proxies
This will return array of your proxies, that is current available.
ProxyManager::getAllProxies();
- Check proxy is alive
This will try to connect to provided URL through your proxy.
$proxy->checkConnection(string $url = "https://www.google.com/", string $method = "GET", int $timeout = 1);
- Get proxy information
This will return array with proxy info. Array contains: proxy type, host, port, username, password, ping in ms (if connection through proxy was tested).
$proxy->getInfo();
- Proxy auth
This will return boolean TRUE if proxy server needs auth or FALSE if doesn't.
$proxy->hasAuth();
TODO
- Make tests.
- Improve documentation.
- Refactor code.
- Make it better.
- Take a cup of coffee.
Contribute
If you would like to help, please take a look at the list of issues or the ToDo checklist.
Pull requests
- Fork and clone.
- Run the tests.
- Create a branch, commit, push and send me a pull request.
License
This project is licensed under MIT license. See the LICENSE file for more info.
Copyright
By tregor 2020
Please let me know, if you have feedback or suggestions.
tregor/proxyman 适用场景与选型建议
tregor/proxyman 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 7 次下载、GitHub Stars 达 1, 最近一次更新时间为 2020 年 06 月 27 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 tregor/proxyman 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 tregor/proxyman 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 7
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 4
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2020-06-27