strange result, every time returned data changes

Hi,

I have a php script connecting to opencalais api

but sometimes it works, somtimes it shows me errors. Everytime i refrech browser (one time i get good result without errors, another time i got errors) This is so strange.

the code is about sending string content from "string array" (containing few words) to opencalais

and i will juste get topics of each word in array. Just that, it's very strange

Thanks

Best Answer

  • Hi,

    As you may expect, given the same input (identical), Calais' output should be the same.

    If you can a run a simple test by repeating the same request with same input we may be able to investigate further (see that maybe some of the requests timeout). In addition, if you can review your HTTP request log (F12->network tab) you may see the actual errors returned from Calais which I hope amount to timeout in which case you will have to implement retries if you must have a response or skip if the response is not crucial.

    At any rate, given the error message above a "null check" on the array will help you avoid this error.

    Regards.

Answers

  • Hello Memane,

    As you justly expect seems like an easy task indeed...

    So Let's try to figure out what is going wrong here:

    1. Please provide your php code snippet that makes the calls to the opencalais API
    2. Please provide a sample of error type you get in this process (if more than one kind of errors pleases provide all)

    Please verify that you are providing the authentication Calais token and the rest of the header parameters as you can see from the API documentation and also from an earlier question in this forum.

    At any rate, please provide 1 and 2 and we will try to resolve your issue ASAP.

    Regards,

    Eyal

    FOR: @memane

  • Thanks, here are my 2 files in attachement:fcontext.zip

    Everytime i refrech browser page, i get one of those 2 results (same script of course)

    this one

    image

    or just this result without error:

    Array
    (
    [0] => Politics
    )

  • Any ideas please ?

  • Seems like for one of your inputs you get a Null array (Array # 2)

    Try adding below condition as wrapper for foreach call.

    if(is_array($opencalais_result)|| is_object($opencalais_result) <br />{foreach...  ...}
  • But, if you refrech the page in browser, you will get a good result without changing anything in script. so the probleme is not in array. Or maybe i did not understand you .

  • Like this?



    <?php



    $array1 = array("a","b","c", "d","e","f","g","h", "i","j","k","l","m", "n","o","p","q","r");



    $array2 = array();



    for($i=0; $i<sizeof($array1); $i++) {

    if($i==0||($i+1)%6==0) {

    $array2[] = $array1[$i];

    }

    }



    print_r($array2);

    ?>



    Prints out: Array ( [0] => a [1] => f [2] => l [3] => r )



    It loops through the first array and only adds to the second array if $i=0 (the first value) or if $i is divisible by 6 with a remainder of 0.
    Write my Dissertation Source(s):
    http://www.w3schools.com/PHP/php_operato.