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.
}
  • 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 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 at 1: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 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 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 at 20:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.