Giter VIP home page Giter VIP logo

guzzle-tor's Introduction

GuzzleTor

Build Status

This Guzzle middleware allows to use Tor client as a proxy

function get_tor_ip()
{
    $stack = new HandlerStack();
    $stack->setHandler(new CurlHandler());
    $stack->push(Middleware::tor());
    $client = new Client(['handler' => $stack]);

    $response = $client->get('https://check.torproject.org/');

    if (preg_match('/<strong>([\d.]+)<\/strong>/', $response->getBody(), $matches)) {
        return $matches[1];
    } else {
        return null;
    }
}

Get started

  1. Install composer

Follow the instruction at https://getcomposer.org/download/

  1. Install guzzle-tor
php composer.phar require megahertz/guzzle-tor
  1. (optional) Copy an example and run
cp vendor/megahertz/guzzle-tor/example.php example.php
php example.php

Symfony 3/4 config DI

services:

    GuzzleHttp\HandlerStack: ~
    
    app.client.tor:
      class: GuzzleTor\Middleware
      factory: ['GuzzleTor\Middleware', tor]

    app.client.handler_stack:
      factory: GuzzleHttp\HandlerStack:create
      class: GuzzleHttp\HandlerStack
      calls:
      - [ push, ['@app.client.tor'] ]

    app.client:
      class: GuzzleHttp\Client
      arguments:
      - {handler: '@app.client.handler_stack'}

    #Aliases
    GuzzleHttp\Client: '@app.client'

Options

General

Middleware::tor($proxy, $torControl)
  • $proxy is tor socks5 port, by default '127.0.0.1:9050'
  • $torControl is Tor control port, by default '127.0.0.1:9051'. Set if you want to change ip (clean circuits)

Request options

$client->get('https://check.torproject.org/', [
    'tor_new_identity'           => true,
    'tor_new_identity_sleep'     => 15,
    'tor_new_identity_timeout'   => 3,
    'tor_new_identity_exception' => true, 
    'tor_control_password'       => 'password' 
]);
Name Description
tor_new_identity Change an identity/IP (clean circuits) before request. If it's set, we send NEWNYM signal to Tor client. Please be aware, that this method does not guarantee that an identity will be changed soon
tor_new_identity_sleep Pause (seconds) between an ip change identity and a request sending
tor_new_identity_timeout Timeout for a Tor control connection
tor_control_password Tor control password
tor_new_identity_exception If true throw TorNewIdentityException if an error was occurred while trying to change an identity

guzzle-tor's People

Contributors

cbastienbaron avatar chooo7 avatar dmitry-kulikov avatar megahertz avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

guzzle-tor's Issues

CURLOPT_PROXYTYPE error

I'm getting the following error "Use of undefined constant CURLOPT_PROXYTYPE - assumed 'CURLOPT_PROXYTYPE' (this will throw an Error in a future version of PHP)"

Need some help please.

Guzzle 7 support?

Hi,

is this package compatible with Guzzle 7?

megahertz/guzzle-tor[v1.0.3, ..., v1.0.4] require guzzlehttp/guzzle ^6.1@stable -> found guzzlehttp/guzzle[6.1.0, ..., 6.5.x-dev] but it conflicts with your root composer.json require (^7.0.1).

InvalidArgumentException

can't pull your repo...

composer.phar require megahertz/guzzle-tor

[InvalidArgumentException]
Could not find package megahertz/guzzle-tor at any version for your minimum-stability (stable). Check the package spelling or your minimum-stability

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.