tregor/proxyman

ProxyMan is OpenSource library for PHP, that makes work with proxies easy!

0.1.4 2020-06-30 11:18 UTC

This package is auto-updated.

Last update: 2020-07-30 11:32:33 UTC


README

Total Downloads GitHub Version Last Commit PHP Req License

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

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.

You can contact me on Facebook or through my email.