abraham / twitteroauth

The most popular PHP library for use with the Twitter OAuth REST API.
https://twitteroauth.com
MIT License
4.3k stars 1.71k forks source link

TwitterOAuth & OpenSSL : errno 104 from Twitter "followers/ids" API call #970

Closed pirmax closed 3 years ago

pirmax commented 3 years ago

Hello,

After looking at what the following error was:

Abraham\TwitterOAuth\TwitterOAuthException: OpenSSL SSL_read: Connection reset by peer, errno 104 in /home/.../vendor/abraham/twitteroauth/src/TwitterOAuth.php:667

I looked on the side of my firewall (which is not activated), but also on the side of the SSL certificate, I did not find much that could help me with TwitterOAuth ...

I am using Laravel workers, and some fail because they encounter this error while executing the job. Many pass but many also fail, and it is quite embarrassing.

Has anyone already encountered this problem (errno 104)?

Here, my PHP code:

$this->twitter = new TwitterOAuth(
    'xxx',
    'xxx',
);

$this->twitter->setTimeouts(30, 30);

$this->twitter->setOauthToken(
    'xxx',
    'xxx',
);

$followers = $this->twitter->get('followers/ids', [
    'user_id' => $twitterId,
    'cursor' => $cursor,
    'count' => $count,
]);

dd($followers);

Thanks, Maxence.

mfn commented 3 years ago

Many pass but many also fail, and it is quite embarrassing.

I have this as a regular occurrence with Twitter (I've access to a system doing lots of API calls to a lots of different social media APIs, but Twitter stands out with this problem).

The only way to deal with this is a smart system with retries: check the error, retry up to n tries, etc.

pirmax commented 3 years ago

The problem with trying again is that it loops in a void, the error is never resolved.

mfn commented 3 years ago

My experience is that these errors are temporary and I've seen first hand that retrying "solves" an API interaction.

For example big videos which need to be uploaded it chunks failed due to this, but once retry was added, the respective chunks were tried again and it "just worked" in the end.

abraham commented 3 years ago

This is typically caused by connection issues between your servers and Twitter or Twitter servers. I don't think there is much this library could do. You could try automatically retrying failed requests once.