Skip to content

Default 2 seconds connection timeout value too low? #55

Closed
@enekochan

Description

@enekochan

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions