0

This might sound like a silly question that is probably just part of the HTTP protocol, but might be important to debugging an issue I'm having.

We have some PHP code that uses the php-curl functions to grab a response from an API and save it. The code works on our dev, and staging servers but breaks when it goes to the load balanced production setup. To test my sanity, I pulled a server off the load balancer and ran it again, it didn't produce errors.

So I suspect it's due to the load balancer. When curl is opened does it say, record the IP of the host for return addressing? Could it be grabbing the IP of the load balancer and then returning to any of the arbitrary servers that doesn't have the connection open waiting for a response?

I've seen that there are a handful of ways to address a specific IP/resource behind a Load Balancer, but haven't seen anything in the order of ensuring that responses return to the initiator.

EDIT Specifics: The production site is hosted on 6 nodes with the exact same code behind 1 load balancer on Rackspace. I have 1% control over what that Load Balancer does (like open ports) so thus my need to determine if it's the issue. The curl code is addressing a Third-Party API that we'll have to consider as a black box (who is probably also Load Balanced).

Code with obfuscations/simplifications:

// Check that we have a Video ID value and it's not empty, check if the created date has changed
if (isset($node->field_video_id['und'][0]['value']) && $node->field_video_id['und'][0]['value'] != '' && $node->created != $node->original->created) {


  $result = db_query('SELECT value FROM {livestream_event} WHERE video_id='. $node->field_video_id['und'][0]['value'] . '');

    foreach($result as $item) {
        $event_id = $item->value;
    }

    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, "http://<API IP>/livestreamauth.php");
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    $token_data = curl_exec($ch);
    $token_data = json_decode($token_data);

    // use all the data and persist to db once it theoretically gets back.
}
Aaron Chamberlain
  • 381
  • 1
  • 3
  • 13
  • You may have to reformulate your question, give more specific example, i don't really get what you are asking. The php code with curl is running on the servers behind the loadbalancers? And trying to do a curl request to an API on the load balancer ? A normal loadbalancer will hide the servers behind it, so curl doesn't have to know where to respond, he always talks with the loadbalancer ( if we are talking about an API on loadbalancer ) – Sandor Marton Jan 30 '19 at 23:44
  • 2
    The load balancer decides how traffic returns to the initiator. But this question really isn't useful., and knowing that won't help you solve the problem, whatever it is. You should instead describe the specific problem and error messages that you received. – Michael Hampton Jan 31 '19 at 01:50
  • @SandorMarton Updates included. I figured it would be sufficient without the details because I'm not sure they help. Essentially the question is just "If a curl session is initiated behind a load balancer to a black box server is the response guaranteed to return to the original initiating server?" The reason it's abstract is because no errors are currently thrown. – Aaron Chamberlain Jan 31 '19 at 18:47
  • This doesn't really make any sense. Where else would a response go? Are you actually having a problem? – Michael Hampton Jan 31 '19 at 19:49
  • @MichaelHampton Then disregard the question. I just know I have an error "this service is unavilable" only when behind a load balancer, yet no detailed stack trace information. Yesterday I even furthered the experiment and cloned my staging server where it was working and put it behind a load balancer and got the same issue. Thus the question "If I start a curl http request on server A will it always return to A or might it go to B,C,D,E,F? Does it matter?" – Aaron Chamberlain Jan 31 '19 at 20:16
  • There is no error checking code in what you have posted above. You need to check whether `curl_exec()` returned false, and check `curl_error()` in that case. – Michael Hampton Jan 31 '19 at 20:24
  • Whatever Michael said. Loadbalancer doesn't have any impact on the outgoing curl request. And as he said , you/devs need to check curl_error, how else you/we are supposed to debug a problem ? I don't know Rackspace, might be possible that in this rackspace setup, the outgoing connections are restricted, so you would have to allow somewhere in Rackspace firewall ( but i don't know if such thing exists, as i said i don't know Rackspace ) – Sandor Marton Jan 31 '19 at 23:00

0 Answers0