Request timeout setting

Comments

5 comments

  • Official comment
    Support

    Hi Tarka,

    Thank you putting this forward.
    I will put this to the development team.

    However we are in the midst of refactoring Http layers in some SDKs. So it could take awhile for ALL SDKs to support timeouts.

    In the meanwhile you might be interested in our GitHub deployment.
    Its a really neat way for you to manage post generated tweaks.
    If you like more information on how this works, please let us. We can have one of the members contact you.

    Thanks
    Kartik

    Comment actions Permalink
  • Support

    Hi Again,

    On the second thought, can you possibly patch one of the SDKs with your TimeOut code and send it to us? It might be possible for us to include this in our next iteration. Send the patched SDK to zeeshan AT apimatic.io

    Best Regards

    0
    Comment actions Permalink
  • Tarka L'Herpiniere

    Following up with this. I think having timeout / retry control over calls is especially useful for connections on unstable networks. Developing world cell networks etc. Given that you are using Unirest across all your SDK's here is a possible implementation. (This is for PHP given that I have been looking at your PHP SDK for the past few days.)

        //set HTTP basic auth parameters
        Request::auth(Configuration::$basicAuthUserName, Configuration::$basicAuthPassword);
    
        // **************************************************
        // Custom timeout and retry in case of network issues
        // **************************************************
        Request::timeout(Configuration::$timeout);
    
        // Init a dummy response
        $response = null;
        $response->code = 408;
        $response->body = "Request Timeout";
    
        // Perform at least 1 call and then retry if there is a time out
        $attempts = 1;
        while ($response->code == 408 && $attempts <= Configuration::$retry) {
            try {
                $response = Request::get($_queryUrl, $_headers);
            } catch (\Exception $e) {
                $attempts++;
            }
        };
        // **************************************************
    

    Add the following to the Configuration:

    /**
     * The HTTP request timeout in seconds.
     * @var int
     */
    public static $timeout = 8;
    
    /**
     * Timeout retries.
     * @var int
     */
    public static $retry = 2;
    
    0
    Comment actions Permalink
  • Tarka L'Herpiniere

    Slightly improved version:

    Replace:

    $response = null;
    $response->code = 408;
    $response->body = "Request Timeout";

    with:
    $response = new Response(408, "Request Timeout", "", array());

    0
    Comment actions Permalink
  • Support

    Hi,

    Thanks for the suggested fix. We have added this to our backlog. We will review this in the next sprint.

    Thanks,
    Zeeshan

    0
    Comment actions Permalink

Please sign in to leave a comment.