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 loves dabbling in other languages like Go and Ruby. Technical topics that interest me are monitoring, security and performance. I'm also a stickler for good documentation and clear technical writing.

During the day I lead a team of developers and solve challenging technical problems at Something Digital where I mainly work with the Magento platform. I've also spoken at a number of events.

In my spare time I blog about tech, work on open source and participate in bug bounty programs.

If you'd like to get in contact, you can find me on Twitter and LinkedIn.