Proxying Guzzle Requests Through Tor

Published: December 16, 2018


Guzzle is the de facto library for doing HTTP requests in PHP. There may be cases where you’d prefer not to disclose your IP address when using it. You may also be using 3rd party tools and not be in a great position to introduce the proxying at an application level.

Fortunately, all you need to do is set the ALL_PROXY environment variable when running your code.

Here’s an example…


// guzzle-test.php 


$client = new \GuzzleHttp\Client();
$res = $client->request('GET', $argv[1]);

echo $res->getBody() . PHP_EOL;


$ ALL_PROXY=socks5://localhost:9050 php guzzle-test.php

Happy hacking!

Max Chadwick Hi, I'm Max!

I'm a software developer who mainly works in PHP, but also dabbles in Ruby and Go. Technical topics that interest me are monitoring, security and performance.

During the day I solve challenging technical problems at Something Digital where I mainly work with the Magento platform. I also blog about tech, work on open source and hunt for bugs.

If you'd like to get in touch with me the best way is on Twitter.