APNS + PHP “stream_socket_client(): Failed to enable crypto”

前端 未结 8 2069
醉酒成梦
醉酒成梦 2020-12-14 09:33

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

stream_socket_client(): Failed to enable crypto

The problem

相关标签:
8条回答
  • 2020-12-14 09:49

    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

    0 讨论(0)
  • 2020-12-14 09:55

    My PHP code was generating following error:

    PHP Warning:  stream_socket_client(): Failed to enable crypto in /private/tmp/t.php on line 12
    PHP Warning:  stream_socket_client(): unable to connect to ssl://gateway.sandbox.push.apple.com:2195 (Unknown error) in /private/tmp/t.php on line 12
    PHP Warning:  fclose() expects parameter 1 to be resource, boolean given in /private/tmp/t.php on line 24
    

    The problem was, the damn certificate, expired the day before yesterday! :-) Can you believe this?

    So, I need to recreate my PEM file.

    0 讨论(0)
  • 2020-12-14 09:55

    It is not necessary recreate your pem file

    that error happens when you use an incorrect PassPhrase

    regards Emiliano

    0 讨论(0)
  • 2020-12-14 09:55

    I had this problem. Disappeared after giving write permission for 'everyone' for the .pem file.

    0 讨论(0)
  • 2020-12-14 09:59

    I tried examples from book of Marin Todorov iOs 6 by Tutorials. And before I could send push notifications for automatical update I had a lot of headache cause of handshake error - stream_socket_client(): Failed to enable crypto.

    I did all of what I found in Stackoverflow - changed permissions on certificate and others.

    What I did eventually?

    I created selfsigned SSL certificate and setup Apache for serving SSL.
    Also I changed SSL protocol from ssl to tls in hostname:

    tls://gateway.push.apple.com:2195
    

    After that service works.

    0 讨论(0)
  • 2020-12-14 10:00

    few checks :

    1. device token should be - with out spaces and with out < or >
    2. make sure the path of certificate is correct and expired date of it.
    3. make sure the passphrase you are using is the one u used to make certificate
    0 讨论(0)
提交回复
热议问题