3

References:

http://docs.guzzlephp.org/en/stable/request-options.html#proxy

Set proxy in Guzzle

Env :

GuzzleHttp/6.2.1 
curl/7.47.0 
PHP/7.1.3-3+deb.sury.org~xenial+1

I am trying to use proxy server with async Guzzle calls.

I have discovered that when I set proxy when creating a client, it works.

e.g.

new Client(['proxy' => 'tcp://64.140.159.209:80'])

However when create a client with no options .. and then set proxy on Request, proxy is not used at all, and guzzle makes a direct connection from client machine to server machine. That is confirmed by hitting http://httpbin.org/ip and inspecting the Origin returned by httpbin.

I need the ability to set proxy on each request.

Here is relevant code:

$client = new Client();

$request = new Request(
                       'GET', 
                       'http://httpbin.org/ip',
                       ['proxy' => 'tcp://64.140.159.209:80']
                      );

$client->sendAsync($request)
                ->then( 
                        ...closure here 
                        // process here 
);
Scalable
  • 1,550
  • 4
  • 16
  • 29

1 Answers1

2

Hope this helps for someone.

The document http://docs.guzzlephp.org/en/stable/request-options.html#proxy only lists creating a new request from a client.

That means I understood the usage wrong. I was creating new Request directly and passing third param with proxy info expecting that to be changed per request within a single client. It looks like that proxy is set on per client basis, even if you are making asynchronous calls.

So I had to modify my application to use a new client per async request.

Scalable
  • 1,550
  • 4
  • 16
  • 29