#1
  1. No Profile Picture
    Contributing User
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Dec 2004
    Posts
    2,868
    Rep Power
    368

    Calling functions of API - high load = wrong order?


    Ok

    I call an API with three methods: login, send_details(), logout. I do this every time a user comes to my site and submits his details.

    Under "heavy" load what seems to be happening (by looking at the API logs) that for some reason, my webserver/php page executes logout() function before send_details() function.

    so my question is, is this possible? I am under the impression my second call, even if it takes a minute, surely php will wait for it before executing the next set of "instructions"?

    I can issue a sleep of 20~ seconds between the 2nd/3rd calls but under high load the time is already too high.

    here is my code

    PHP Code:
    $result $client->logon($logonparams);
    $sessionid $result->logonReturn;
        
    try {
           
    $result $client->send_details($params);
           
    $userID htmlspecialchars($result->user_id);
    } catch(
    Exception $e) {
        
    $email_message $e->getMessage() ."\n\n";
        
    mail(".....","subject"$email_message );
    }
        
    // now logout
    $params = array('session' => $sessionid);
    $client->logout($params); 
    I would also like to add that it is actually the try/catch block that sends me an error message "Bad Gateway" and asking the techies for the log, it seems this bit is happening AFTER log out (only because the time in the log says so e.g.:

    Code:
    xap02-3: 11:42:14,425 INFO  send_details(";jsessionid=6CC1BFAE155DF13FD699D8240AE2978B;api03$....","xml"..","..",..) => "Error:"Unexpected eC-M Reply Code: 500"" 82797ms
    
    xap01-4: 11:41:12,898 INFO  logout(";jsessionid=6CC1BFAE155DF13FD699D8240AE2978B;api03$...") 15ms
    
    xap01-3: 2013-06-25 11:40:51,550 INFO  logon("...","...","...") => ;jsessionid=6CC1BFAE155DF13FD699D8240AE2978B;api03$... 42ms
  2. #2
  3. Mad Scientist
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Oct 2007
    Location
    North Yorkshire, UK
    Posts
    3,660
    Rep Power
    4123
    Are the logs coming from the service where the API is?

    Look at it this way - yo're sending 3 separate requests to the API service. If you communicate with the api over http then these really are 3 separate requests.

    So, what if the api server writes the log on completion of the request? If the process continues to run after issuing your script a response and allowing your script to move on then your script will issue the logout command while the api send_details method is still running.
    I said I didn't like ORM!!! <?php $this->model->update($this->request->resources[0])->set($this->request->getData())->getData('count'); ?>

    PDO vs mysql_* functions: Find a Migration Guide Here

    [ Xeneco - T'interweb Development ] - [ Are you a Help Vampire? ] - [ Read The manual! ] - [ W3 methods - GET, POST, etc ] - [ Web Design Hell ]
  4. #3
  5. No Profile Picture
    Dazed&Confused
    Devshed Novice (500 - 999 posts)

    Join Date
    Jun 2002
    Location
    Tempe, AZ
    Posts
    501
    Rep Power
    127
    Hmm, just food for thought:

    If you were to provide an alternative means of authentication, such as allowing the client to send the login info as a header with every request, you could reduce this from 3 calls to 1.

    On the API side, if that's how they authenticate then their "session" exists only for the duration of that call. So it gives the client the flexibility of using a single stateless call, or have state (ie, the session) over multiple calls.

    Comments on this post

    • Northie agrees : Great idea. I always forget about the headers!

IMN logo majestic logo threadwatch logo seochat tools logo