APN php code giving Warning: stream_socket_client() [function.stream-socket-client]: unable to connect to ssl://gateway.sandbox.push.apple.com:2195
Assuming your server has the right ports open, "Connection Refused" usually hints at an invalid .PEM file or an incorrect passphrase. Make sure that when you open the .PEM file, the header looks something like this :
Bag Attributes
friendlyName: Apple Development IOS Push Services: com.yourapp.app
localKeyID: A8 77 BC 0C 2E 81 10 6E 78 9F XX XX XX XX XX XX
subject=/UID=com.yourapp.app/CN=Apple Development IOS Push Services: com.yourapp.app/C=FR
issuer=/C=US/O=Apple Inc./OU=Apple Worldwide Developer Relations/CN=Apple Worldwide Developer Relations Certification Authority
followed by a key which should then be followed by a header that looks like this for your private key :
Bag Attributes
friendlyName: Joe Black
localKeyID: A8 77 BC 0C 2E 81 10 6E 78 9F XX XX XX XX XX XX XX XX
Key Attributes: <No Attributes>
I suggest you also remove the passphrase to reduce the potential error sources.
How to use Apple Push Notifications if you can't use port 2195?
In order to send the notifications to the device need to enable 2195 port in the firewall.
For security reasons some organizations disabling these ports in the firewall.
2196 port is used for feedback services and this port also should open in the firewall.
Without opening these ports messages cannot deliver to APNS.
PHP fails socket connection with Apple notification gateway
Some random finding from the internet which could help:
It may be a certificate problem. Try the stream options
allow_self_signed
andverify_peer
to check that.Try to use explicitely
sslv2://
orsslv3://
?Permission problem on "/dev/urandom"
stream_socket_client unable to connect (connection timed out)
I had fixed the issue by opening the port 2195 on the production server. You can verify by following command $telnet gateway.push.apple.com 2195
-bash-3.2# telnet gateway.push.apple.com 2195
Trying 17.149.38.141...
Connected to gateway.push.apple.com (17.149.38.141).
Escape character is '^]'.
Connection closed by foreign host.
Related Topics
Appending a Value of a Variable to a Variable Name
PHP Datetime::Createfromformat in 5.2
Shell_Exec() Timeout Management & Exec()
Xpath in Simplexml for Default Namespaces Without Needing Prefixes
Html2Pdf in PHP - Convert Utilities & Scripts - Examples & Demos
Phpdoc for Variable-Length Arrays of Arguments
How to Access MySQLi Connection in Another Class on Another Page
Change "Billing Details" Text to "Shipping Details" on Woocommerce Checkout Page
Google Calendar API Batch Request PHP
Using PHP, How to Insert Text Without Overwriting to the Beginning of a Text File
How to Validate Non-English (Utf-8) Encoded Email Address in JavaScript and PHP
PHP Xpath - Find Element with a Value and Also Get Elements Before and After Element
Why Is My Database Backup Script Not Working in PHP
What Does the "&" Sign Mean in PHP