2

I have some troubles with a custom written API.

It happens when I do an API call, it randomly returns nothing. This is now temporary fixed by doing the same API call until something is returned.

The API calls are always the same and the code itself (SDK and API) does not throw any errors.

I'm thinking of a connection problem?

Is there anyone who has an idea how to fix this properly?

SDK Code:

function doGetRequest($request, $params = array()) {
$request = 'http://www.xxx.be/api/nl/'.$request.'?'.http_build_query($params);

$curl = curl_init();
curl_setopt_array($curl, array(
    CURLOPT_RETURNTRANSFER => 1,
    CURLOPT_URL => $request,
));
$resp = curl_exec($curl);
curl_close($curl);

return json_decode($resp);

}//doGetRequest

API Code:

public function getCompanyIdByUserId($userId) {

    $sql = '
    SELECT
        company_member_company_id 
    FROM
        ka_company_members
    WHERE
        company_member_member_id = ?
    ';

    return db::getValue($sql, $userId);

}//getCompanyIdByUserId

Curl_info gives me this when there's nothing returned

["url"] => string(123) "http://xxx/nl/urldata/mijn_webcasts/43?key=xxx"
  ["content_type"]=>
  string(29) "text/html; charset=iso-8859-1"
  ["http_code"]=>
  int(500)
  ["header_size"]=>
  int(199)
  ["request_size"]=>
  int(154)
  ["filetime"]=>
  int(-1)
  ["ssl_verify_result"]=>
  int(0)
  ["redirect_count"]=>
  int(0)
  ["total_time"]=>
  float(0.005005)
  ["namelookup_time"]=>
  float(1.4E-5)
  ["connect_time"]=>
  float(4.8E-5)
  ["pretransfer_time"]=>
  float(7.5E-5)
  ["size_upload"]=>
  float(0)
  ["size_download"]=>
  float(603)
  ["speed_download"]=>
  float(120479)
  ["speed_upload"]=>
  float(0)
  ["download_content_length"]=>
  float(603)
  ["upload_content_length"]=>
  float(0)
  ["starttransfer_time"]=>
  float(0.004986)
  ["redirect_time"]=>
  float(0)
  ["redirect_url"]=>
  string(0) ""

  ["certinfo"]=>
  array(0) {
  }

}
MrSkippy
  • 348
  • 4
  • 17
  • It has nothing to do with the code. take API call "http://xxx/api/contents/". The code there just returns an array ['content', 'content2']. This works perfectly but sometimes, on random moments, the API returns nothing. The SDK only makes a simple cURL get request – MrSkippy Jan 18 '17 at 12:40
  • I Added the SDK and API codes that matter – MrSkippy Jan 18 '17 at 12:44
  • Add `$info = curl_getinfo($curl);` after your your `curl` request (before closing curl) and report back the `var_dump($info)` when your request does not return anything. – Kitson88 Jan 18 '17 at 12:52
  • @Kitson88 I updated my question. – MrSkippy Jan 18 '17 at 13:02
  • 1
    Do you see the part where it says `http_code` = 500? This means Internal Server Error so it's most likely an Apache/IIS issue and not an error client side which I suppose helps a little. – Kitson88 Jan 18 '17 at 13:05
  • Hmm? But how is it possible that it works all the time, and at random moments it gets a server error? – MrSkippy Jan 18 '17 at 13:10
  • I can't tell you why as I have no access to your server. All I know is that the issue is server related. You need to start working through your web server logs. if it's Apache then take a look at this answer to get your started: http://stackoverflow.com/questions/4731364/internal-error-500-apache-but-nothing-in-the-logs – Kitson88 Jan 18 '17 at 13:13
  • Thanks for your comments! The apache logs shows me: client denied by server configuration – MrSkippy Jan 18 '17 at 13:20
  • 1
    http://stackoverflow.com/questions/8413042/client-denied-by-server-configuration – Kitson88 Jan 18 '17 at 13:22
  • Thanks you @Kitson88 – MrSkippy Jan 18 '17 at 13:56
  • No worries! I've just noticed your external IP is showing in the curl-info. I would probably remove that from your question especially as some form of key is also showing in the URL. – Kitson88 Jan 18 '17 at 13:58

0 Answers0