Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
623 views
in Technique[技术] by (71.8m points)

ios - APNS + PHP "stream_socket_client(): Failed to enable crypto"

I'm having trouble with using APNS with PHP and getting the following message:

stream_socket_client(): Failed to enable crypto

The problem only happens sometimes, and other times it would actually send the push.

Since I have the test script on a loop of 10 iterations, I would sometimes get this:

stream_socket_client(): SSL: Connection reset by peer

I'm testing using the sandbox server tls://gateway.sandbox.push.apple.com:2195

Here is what I tried:

  • I tried to reissue the PEM and all certificates with it.
  • I played around with the request protocol sslv3:// and tls://.
  • I played around with the passphrase (push worked without the passphrase btw)
  • I tried searching stackoverflow for a solution and nothing worked.
  • Checked pem file permissions 644
  • Checked pem parent directories permissions 755

It seems that all the solutions I found on Google and SO are people having problem pushing altogether.

I feel like the service is rate limited maybe? Because we waited a while (around 15 minutes) and then tried it again, and was able to successfully push around 100 messages until I started getting that message again.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

The sandbox push service is rate limited. I have experienced this myself when testing but have never encountered any such limit using the production API.

You might also be hitting their other protections.

Are you opening a connection, sending a message, closing connection and then looping and doing it all over again?

That will get your notifications dropped. Apple wants you to send several push notifications using the same connection, not a new one each time.

Best Practices for Managing Connections

You may establish multiple connections to the same gateway or to multiple gateway instances. If you need to send a large number of remote notifications, spread them out over connections to several different gateways. This improves performance compared to using a single connection: it lets you send the remote notifications faster, and it lets APNs deliver them faster.

Keep your connections with APNs open across multiple notifications; don’t repeatedly open and close connections. APNs treats rapid connection and disconnection as a denial-of-service attack. You should leave a connection open unless you know it will be idle for an extended period of time—for example, if you only send notifications to your users once a day it is ok to use a new connection each day.

From Apple Docs @ https://developer.apple.com/library/ios/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/Chapters/CommunicatingWIthAPS.html


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...