SitePoint Sponsor

User Tag List

Results 1 to 2 of 2

Thread: HTTP Post

  1. #1
    SitePoint Enthusiast sportstoto3368's Avatar
    Join Date
    Apr 2004
    Location
    World
    Posts
    64
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question HTTP Post

    Posting from Singapore Page

    $postfields= null;
    $postfields["action"] = "doGetCountryList";
    $postfields["SecretKey"] = "SFGSFGFB";
    $results= $objCURL->PostAndReceive($postfields, api_url_US);
    $countryArray= $results["country"];
    array_pop($countryArray);


    api file located in US Server

    switch ($_REQUEST['action'])
    {

    case 'doGetCountryList':
    {

    //perform query and return data

    while (!$rs->EOF) {
    $key= $rs->fields['sKey'];
    $value= $rs->fields['sValue'];
    echo '' . $key . '=' . $value . ';' ;
    $rs->MoveNext();
    }

    break;
    }
    }

    Dear all,

    My problem:

    I use a centralized db located in US server.

    In order for my webpage hosted in Singapore to get data from this centralized db, I use Curl, HTTP Post to send data to api file in US (this file get the param, perform query to local db in US Server, return back data to the page in singapore)

    I'm facing problem of missing data returned. Possible due to the recent international ISP trunk link issue (slow).


    1st issue faced is:

    The page load until half then the bottom part blank...
    I solve this by using set_time_limit(0);


    2nd issue faced is:

    The signup page located in Singapore will do extensive api call to US server (6-7 times to retrieve data from US server).
    The respond from US server is slow, the page can load until the end, but certain returned data is missing.


    I thought the HTTP post will only consider complete when the data fully returned to signup page in SG?
    How come the page loading in Singapore is shown as DONE, even the data returned from US server to SG is not fully complete?


    Example Scenario: Country from Alaska to Zimbabwe, it only load Alaska to Singapore (all other countries is truncated)

  2. #2
    SitePoint Wizard bronze trophy
    Join Date
    Jul 2008
    Posts
    5,757
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    There's so many potential areas, but I think you should look at this
    http://www.php.net/manual/en/function.curl-setopt.php

    Probably most glaring is CURLOPT_TIMEOUT, but theres also some CURL_LOW_SPEED_* settings too, I'm not sure if they have any active default values, and I'm not sure what happens when curl just gives up(maybe it returns partial content, you could test this by making a dummy script which just sleep()'s for a long time).

    I would look into those settings. I would make sure the script which serves the response makes sure it sends a proper content-length header, it might help curl. I would also compress the response since you have very high transfer overhead, you want to minimize the number of bytes, to increase speed and reliability. You could use gzip/deflate/zlib on max compression setting.

    You could also ditch curl and use fsockopen() as it has less automatic functionality. This could potentially allow you identify and handle error conditions more effectively if you know what you're doing.

    I would also make absolute sure your us script is not the problem. Maybe have the singapore script send some type of unique request_id with the request. The us script will log this id along with every bit of data it outputs back, to a log file. Then when you detect a failed transaction, that id can be used to see if the us script really did it's job.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •