Closed chekalsky closed 9 years ago
$notificato = new Notificato();
$certificateProd = $notificato->createCertificate($certDir . '/xxx.cer');
$certificateDev = $notificato->createCertificate($certDir . '/yyy.cer');
// Build the base alert
$builder = $notificato->messageBuilder()
->setExpiresAt(new DateTime('+12 hour'))
->setAlert($alertText)
->setSound(($isSound) ? 'default' : null)
->setPayload($customParams)
->setBadge($badgeCount);
// Adding alerts to queue
foreach ($tokens as $deviceToken) {
$builder->setDeviceToken($deviceToken['token']);
if ($deviceToken['isDeveloper'] != 1) {
$build = $builder->setCertificate($certificateProd)->build();
} else {
$build = $builder->setCertificate($certificateDev)->build();
}
$notificato->queue($build);
}
// Sending
$notificato->flush();
Thanks for reporting your problem.
I'm wondering if you have some more information on when these warnings happen. Do they already happen when you call flush for the first time? Or do they only show up on later batches? Could you also tell me what PHP and OpenSSL version you are using?
Could have something to do with Apple closing the connection due inactivity or due SSL weirdness where we have to do a retry.
PHP 5.4.34-0+deb7u1 OpenSSL 1.0.1e
It is rare problem, not every time. But possibility of meeting this warning increases when I add to $tokens more items (etc more than 100). But sometimes everything is OK.
I am not sure if it is happens for first flush or not, it is running in background in gearman. But I think there is possibility of that is happens on second and third flush().
Just now got this error once again.
It is happening in the endless cycle until php's timeout. It is put failed message into queue again and again and again, but the strange thing is that messages are duplicated on device and coming over and over again.
I think you should create some emergency plan for this scenario or solve the reason of error in fwrite().
P.S. I will move to another php library, I hope my report helps.
UPD. Ugh, there is no other cool libraries on github for push alerts, please, could you fix this issue? :-)
Thanks for the additional info! I found stack overflow posts like the one you mention here indeed, seems like we have to handle SSL write errors better. The hard thing is that I don't have a good reproduction path yet. :(
I think handling these errors by reconnecting would maybe already fix it. I'll take a look. :)
Ok, made some changes! Could you test the develop branch by changing your composer file? Would be great to know if this fixes the issue for you.
You can do this by changing the composer line to:
"wrep/notificato": "dev-development"
What was happening:
What I've changed it to:
Ok, and I'll increase count of notifications sending through one connection to increase possibility of error :)
Well, it works but I think we should wait couple of days to make this thing right.
Great, thanks for testing! I'll wait a few days and if I don't hear of any errors from you I will release a new version.
Keep me posted about the results of this new version. :)
@chekalskiy How does it look? Everything still running stable? Have you seen any of these SSL warnings so far?
I am little away now but I 99% sure that everything is OK. I can tell more after next Tuesday.
Good to know! Thanks.
I'll create an official release asap, let me know if you experience any issues.
:+1:
Did you forget about new release?
I did not forget, but thanks for the reminder. :) Version 1.1.1 with this fixed is now available.
WARNING
fwrite(): SSL operation failed with code 1. OpenSSL Error messages: error:1409F07F:SSL routines:SSL3_WRITE_PENDING:bad write retry
/Wrep/Notificato/Apns/Gateway.php at line 107. {"messageEnvelope":"[object](Wrep\Notificato\Apns\MessageEnvelope: {})","binaryMessage":null,"bytesSend":0,"retryMessageEnvelope":"[object](Wrep\Notificato\Apns\MessageEnvelope: {})"}