Using VPS Multiple IPs for a php script

kingfish

Champion of Awesome
Sep 25, 2007
3,497
57
0
So I've got this php script that queries a web service a lot. I'm running into errors because I query it too fast and I thought that perhaps it bases this on IP.

I run the script from the command line so it only uses the base IP of the vps right now. I've got a VPS and 4 IPs I can use for it but I'm not sure how to make php use the different IPs. I'm no linux guru so this is stumping me. I suppose one method is install a proxy that routes through the other IPs maybe then I can spawn off subprocesses that use them appropriately is there any other way to do this?
 


Hmm I implemented this and it doesn't appear to work even if I set that option to another one of my IPs it seams it is still trying to use the original ip only
 
Actually it works when I test it but the web service sees through it somehow I guess
 
If you run into any problems, and your VPS is setup on a control panel such as DirectAdmin or Cpanel, then depending on how PHP is setup you might not be able to run on more than the account-assign-IP. Just something to note if you do run into a problem.
 
Interesting. How can that be tested before you get too far down the road? I was considering rewriting one of my scrapers taking advantage of this.
 
Well you could setup a php.php file on another server with <?php phpinfo(); ?> in it, and do a couple grabs from a couple different IP addresses and look for the value of _SERVER["REMOTE_ADDR"] in the results. Though I would think the error log would reflect the inability to use an IP outside of a users/account range, than to just use the default.
 
Good idea. I'll try that. Hell, I'll just have it output remote_addr on the page on the different server and then scrape that. Two birds with one stone. :)
 
Well the check for remote_addr has to be done on the server you're scraping not the server doing the scraping.
I know. I have a page called getip.php on another server, that outputs the remote_addr of whoever visits it. Then on my VPS (different server), I'm hitting that page with cURL and grabbing it echoing remote_addr. So if I loop it, and I've set the curl_opt to an array of random IPs, I should see that randomized array coming back, right?
 
I know. I have a page called getip.php on another server, that outputs the remote_addr of whoever visits it. Then on my VPS (different server), I'm hitting that page with cURL and grabbing it echoing remote_addr. So if I loop it, and I've set the curl_opt to an array of random IPs, I should see that randomized array coming back, right?

Yea that would work.
 
Well, shit. It's the same IP every time. That sucks. I really don't want to ask support how to get around it, because they might start asking questions.
 
It looked like array_rand() can't take an array() inside of it but rather a variable, where as this instead works:

$ips = array("ip1","ip2","ip3","ip4");
shuffle($ips);
curl_setopt($ch, CURLOPT_INTERFACE, $ips[0]);

But course the VPS I tested it on was not a WHM/Cpanel VPS, (has no control panel).