PHP code example of megahertz / guzzle-tor

1. Go to this page and download the library: Download megahertz/guzzle-tor library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

megahertz / guzzle-tor example snippets


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;
    }
}

Middleware::tor($proxy, $torControl)

$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' 
]);
bash
  php composer.phar 
bash
  cp vendor/megahertz/guzzle-tor/example.php example.php
  php example.php