edamov / pushok

PHP client for Apple Push Notification Service (APNs) - Send push notifications to iOS using the new APNs HTTP/2 protocol with token-based (JWT with p8 private key)
MIT License
368 stars 119 forks source link

curl error when pusing to apns #175

Open algesiaResidue opened 1 month ago

algesiaResidue commented 1 month ago

Sometimes, We got this error when pusing to apns: Operation timed out after 0 milliseconds with 0 out of 0 bytes received. The frequence is once or twice a day.

edamov commented 1 month ago

It is hard to fix such error. Maybe the problem is on apple server side. The only way I see is to add try/catch block and send request again in case of error. You can implement it on your side. But also I may try to add this logic in library. Can you somehow store the whole response (status code, headers, body) from APNS and send me?

algesiaResidue commented 1 month ago

unfortunatly, curl http code is 0, thus throwing this exception in Client.php line 161, and there is no valid response.

algesiaResidue commented 1 month ago

maybe adding a retry function when curl get code 0 is a good idea.

dlucian commented 1 month ago

But then, since the whole sending crashes on one timeout, one would need to check which notifications where sent and re-try the sending with just the ones that were not sent, right?

Which can't be done, since Client::push() doesn't return the responses anymore, but throws instead. So we don't know which notifications were sent and which not. Or am I missing something?

algesiaResidue commented 1 month ago

But then, since the whole sending crashes on one timeout, one would need to check which notifications where sent and re-try the sending with just the ones that were not sent, right?

Which can't be done, since Client::push() doesn't return the responses anymore, but throws instead. So we don't know which notifications were sent and which not. Or am I missing something?

You can't just throw this exception, but handle it yourself instead. When curl http code got 0, you should add that notification to multi curl handler again to be sent later.

dlucian commented 1 month ago

But then, since the whole sending crashes on one timeout, one would need to check which notifications where sent and re-try the sending with just the ones that were not sent, right? Which can't be done, since Client::push() doesn't return the responses anymore, but throws instead. So we don't know which notifications were sent and which not. Or am I missing something?

You can't just throw this exception, but handle it yourself instead. When curl http code got 0, you should add that notification to multi curl handler again to be sent later.

No, the Client class throws \Exception, not me. And when it it's thrown, there's no list of successfully sent notifications, so I don't know which to retry.

algesiaResidue commented 1 month ago

You can rewrite this method, and add retry mechanism. I just did this, and the error never affected my pushing project again lol.

algesiaResidue commented 3 weeks ago

Sorry for the misinformation, after adding the retry mechanism ,this issue still bothers me, apns server will continue to deny this notification in next few minutes which means you need retry through this time span. I've figure out a solution, I recommand you use swoole http2 client and connection pool to maintain these connections. you can refer to https://wiki.swoole.com/zh-cn/#/coroutine_client/http2_client for more information.