Question

Outbound IP address on Load Balancers using PHP curl

I have this scenario… 2 droplets on the same region, connected to Load Balancer… How is that possible that when sending a request via PHP curl the API end point gets the droplet IP address? I want to split the amount of requests to the API I do per IP, so I don’t have issue of getting blocked… Is that possible?

Thanks in advance.


Submit an answer

This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Accepted Answer

Greetings!

If I understand correctly, you have an outbound job on your droplet which reaches out to an external API. You want to balance that task so that the requests do not all come from the same IP. If I am understanding this correctly, there may not be one correct answer from a generic perspective that can be guaranteed to fit your situation.

These are a couple of thoughts:

  1. If it were a cron job, for example, you could just do the cron job half as often from two servers.

  2. If you created multiple proxies for the API requests you could then put those behind an haproxy instance. So like let’s say the endpoint is api.externalservice.com, I could make:

- haproxy (apiproxy.myservice.com)
- - proxy1 (proxy1.myservice.com) -> api.externalservice.com
- - proxy2 (proxy2.myservice.com) -> api.externalservice.com

Then I could have haproxy balance all outbound traffic through the two servers under it. Setting this up isn’t something I could directly advise on as I’m unfamiliar with your specific situation, but in theory a stack like this could function quite well. You can use haproxy for just about anything that requires load balancing. You can see me doing it with SMTP here: https://d.pr/i/4Lfbtq

Jarland

Want to learn more? Join the DigitalOcean Community!

Join our DigitalOcean community of over a million developers for free! Get help and share knowledge in Q&A, subscribe to topics of interest, and get courses and tools that will help you grow as a developer and scale your project or business.