/** * @expectedException \GuzzleTor\TorNewIdentityException */ public function testExceptionWhileNewIdentity() { $stack = new HandlerStack(); $stack->setHandler(new CurlHandler()); $stack->push(Middleware::tor('127.0.0.1:9050', 'not-existed-host:9051')); $client = new Client(['handler' => $stack]); // Throw TorNewIdentityException because of wrong tor control host $client->get('https://check.torproject.org/', ['tor_new_identity' => true, 'tor_new_identity_exception' => true]); }
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; } }