GuzzleHttp 6 choose local public ip to send request

Viewed 184

I use GuzzleHttp to send request to an external API. This API implements a throttling to limit requests to a maximum per second per distant IP. I will built a local queuing component but I want to speed up requests and use some of my public IPs to load-balance or use them successively.

I'm looking for a solution to create GuzzleHttp client and force it to use one of my local public IP or another.

On a general PHP basis, I found here a way to bind a socket in a stream context, using file_get_contents

I browsed GuzzleHttp and PSR-7 code and found that it uses StreamInterface that may be wrapped and may be use a stream context in a similar way.

But I can't find a way to do so. Can you give me an example how to implement that ?

1 Answers

I don't know if it'll help but with curl you can do it like this:

curl --interface zz.zz.zz.zz http://example.com/

I also need to bind Guzzle to one of my IP addresses but didn't find the solution yet...

Related