Download the PHP package unique/proxy-switcher without Composer

On this page you can find all versions of the php package unique/proxy-switcher. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package proxy-switcher

PROXY SWITCHER

A component for making HTTP requests using proxies. Allows for easy switching between different proxy servers.

Installation

This component requires php >= 7.4. To install it, you can use composer:

Usage

No proxies

You can use this component with no proxies.

Single Proxy

Or you can specify a single proxy to be used for all requests.

Multiple Proxies and switching between them

Whenever you need to have a list of available proxies and switch between them either after a certain number of requests or when a proxy is blocked/not working, you can use ArrayProxyList.

When you are using ArrayProxyList, you can use Transport::$switch_transport_min and Transport::$switch_transport_max to specify the number of requests that needs to be made before a forced proxy change will be made. Proxies will be chosen in the order they were provided. If a proxy fails, it will be marked as failed and a switch will be made to the next one. If a proxy fails ArrayProxyList::$max_transport_fails times (default 3) it will be marked as invalid and will not be retried.

You can also specify Transport::$next_timeout_min and Transport::$next_timeout_max to randomize a number of requests after which a timeout will be made. The length of timeout can be specified by using Transport::$sleep_time_min and Transport::$sleep_time_max which sets a minimum and maximum of seconds to timeout.

Passing arguments to GuzzleHttp or chossing another Client

Although the component has been designed to use GuzzleHttp\Client class for making requests, in theory you could choose to use any object that implements request() method. You can do this by passing client_options attribute to the Transport constructor:

You can also pass other attributes to the constructor of the client:

If no class attribute will be specified \GuzzleHttp\Client will be used by default.
You could event pass a Client object instead of it's configuration:

Making requests

Under the hood the component uses GuzzleHttp for making requests, so you can pass any options that you normally would as a third parameter.

However, a few options: connect_timeout and proxy are set automatically based on the attributes of Transport object.

Also, Cookie header is taken from Transport::$cookie

You can read more about making requests using GuzzleHttp, here: docs.guzzlephp.org

Creating your own proxy list component

If you need to do more logic than some basic switching, you can write your own ProxyList class by extending AbstractProxyList. This can be helpful if you have the list in a DB and want to keep track on the servers.

Documentation

Transport attributes

int $next_timeout_min = 2000 and int $next_timeout_max = 5000

After a random amount (in the range of min/max) of requests a timeout will be made. In order to turn this off, set $sleep_time_min and $sleep_time_max to zero.

int $sleep_time_min = 2 * 60 and int $sleep_time_max = 5 * 60

The amount of seconds to sleep after a timeout has been reached. The real amount of seconds to sleep will be randomized in this range. Can be set to zero, if no such timeout needs to be made.

int $switch_transport_min = 400 and int $switch_transport_max = 800

Minimum and maximum requests between a proxy switch. If both set to null, the proxy will only be switched once it fails.

int|null $max_proxies_in_a_row = null

Specifies how many proxies can be tried during a single request, before giving up and throwing an Exception. This can be used as a safety measure, so that in stead of endlessly going through all the proxies specified, assume that there is something wrong after this many requests fail. (Like maybe internet connection failure, bad address, etc..)

int $connect_timeout = 1

Default connection timeout for each request. Can be overriden by passing options to Transport::request() method.

int $timeout_after_request = 1

Specifies the amount of seconds to wait after each successful request, in order to prevent flooding.

string $cookie = ''

A cookie string to use for requests.

SingleProxyList|ArrayProxyList|array|null $proxy_list

If specified, object will be used to control proxy switching. You can pass an array only during contruction of the Transport object, for proxy_list object to be constructed automatically. In this case, array needs to contain a ['class'] key.

Transport methods

setProxyList( AbstractProxyList $proxy_list )

Sets the provided proxy list.

getProxyList(): AbstractProxyList

Returns the assigned proxy list object.

request( string $method, $url, array $options = [] ): ResponseInterface

Makes a request to the url, using the provided request method GET/POST. If a proxy_list object was provided during the construction of the object or using setProxyList() method, proxy switching logic will be applied accordingly.

static getInstance( $config = [] ): Transport

Returns a static instance of the Transport class.

setLogger( \Closure $logger )

Sets a logger function for transport and proxy_list. A logger function will receive a single string parameter with a text that needs logging.

on( string $event, $callback )

Sets a new handler for the specified event type.

trigger( string $event_name, EventObjectInterface $event )

Triggers the specified event. The first assigned handler will be called first. If it does not set EventObjectInterface::setHandled() the second handler will be called and so on, until all the handlers have been called or setHandled( true ) has been set.

off( string $event, $callback = null )

Removes an event handler from the object. If no handler is provided all handlers will be removed.

Using events

This component has a very simple event system with two defined events.

You can subscribe to an event by calling Transport::on() method. An event like TooManyRequestsEvent can be set as handled using setHandled( true ) on the passed Event object, in which case the current proxy will not be failed and the component will try to continue using it.

License

This project is licensed under the terms of the MIT license.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.


All versions of proxy-switcher with dependencies

PHP Build Version
Package Version
Requires php Version ^7.4
guzzlehttp/guzzle Version ^7.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package unique/proxy-switcher contains the following files

Loading the files please wait ....