php-rest-api icon indicating copy to clipboard operation
php-rest-api copied to clipboard

Default 2 seconds connection timeout value too low?

Open enekochan opened this issue 7 years ago • 2 comments

I've been having problems sending SMS messages because of connection timeouts. It doesn't happen every time, it's just "random" (my guess just because of the network connection quality "randomness"). Looks like I've been able to fix this using a custom HttpClient with a higher connect timeout value (10 seconds):

use MessageBird\Client;
use MessageBird\Common\HttpClient;

class MessageBird
{
    /** @var \MessageBird\Client $messageBirdClient */
    protected $messageBirdClient;

    public function __construct($key)
    {
        $httpClient = new HttpClient(Client::ENDPOINT, 10, 10); // Change default connection timeout from 2 seconds to 10
        $this->messageBirdClient = new Client($key, $httpClient);
        ...
    }
}

Although this is fine for me, it would make Chat and Voice endpoints not work as addressed in #29 because the endpoints are different and setting a custom HttpClient makes the same client be used in the 3 endpoints, making this solution not perfect for everyone.

The default value for CURLOPT_CONNECTTIMEOUT seems to be 300 seconds, much higher than our 2 seconds. Other language rest API libraries for MessageBird (I've briefly looked at Java, C# and Python libraries) use their HTTP client default values which most of the times AFAIK are set to "infinite".

The last PR that set this value was #28

Having all this in count, may be the default value should be raised. Not just me, I suspect more people may be having the same issue. In that case those 2 lines should be changed and I could provide a PR:

https://github.com/messagebird/php-rest-api/blob/master/src/MessageBird/Common/HttpClient.php#L59

https://github.com/messagebird/php-rest-api/blob/master/src/MessageBird/Client.php#L147

enekochan avatar Nov 11 '17 22:11 enekochan

This may be related to #39 too

enekochan avatar Dec 08 '17 01:12 enekochan

This just hit me too, even though it seems the default timeout has changed since this issue was created.

It would be nice if there was an easier way to configure timeouts, perhaps as an extra option added into the $config array of the Client constructor, both for the connection and regular timeout.

Mark-H avatar Sep 21 '20 20:09 Mark-H

Closing this due to inactivity.

dennisvdvliet avatar Jan 13 '23 07:01 dennisvdvliet