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.

jarland
DigitalOcean Employee
DigitalOcean Employee badge
April 15, 2019
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

Try DigitalOcean for free

Click below to sign up and get $200 of credit to try our products over 60 days!

Sign up

Become a contributor for community

Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.

DigitalOcean Documentation

Full documentation for every DigitalOcean product.

Resources for startups and SMBs

The Wave has everything you need to know about building a business, from raising funding to marketing your product.

Get our newsletter

Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.

New accounts only. By submitting your email you agree to our Privacy Policy

The developer cloud

Scale up as you grow — whether you're running one virtual machine or ten thousand.

Get started for free

Sign up and get $200 in credit for your first 60 days with DigitalOcean.*

*This promotional offer applies to new accounts only.