PHP Script to Send Push Notifications.

Hello I have created an app that sucessfully receives push notifications form pushtry..com I upload the .pem and enter the passphrase, and it works.

I am now taking the same .pem file and passphrase and adding it to a php script. I run it and the script throws an error on the last line shown below. Any help would be graetly appreciated.


As far as the .pem file is concerned I exported the "Apple Development IOS Push Servicer: com.mycompany.myapp" and my associated private key. then converted each to a .pem then concatenated the two files.


$ctx = stream_context_create();

stream_context_set_option($ctx, 'ssl', 'local_cert', 'aps_dev.pem');

stream_context_set_option($ctx, 'ssl', 'passphrase', self::$passphrase);

$fp = stream_socket_client( 'ssl://gateway.sandbox.push.apple.com:2195', $err, $errstr, 60,

STREAM_CLIENT_CONNECT|STREAM_CLIENT_PERSISTENT, $ctx);


Warning: stream_socket_client(): Unable to set private key file `/Users/twolff/Desktop/APNS-PHP/aps_dev.pem' in /Users/twolff/Desktop/APNS-PHP/PushNotifications.php on line 44

Warning: stream_socket_client(): Failed to enable crypto in /Users/twolff/Desktop/APNS-PHP/PushNotifications.php on line 44

Warning: stream_socket_client(): unable to connect to ssl:/

Failed to connect: 0


The telnet test looks good:


telnet gateway.sandbox.push.apple.com 2195

Trying 17.188.165.216...

Connected to gateway.sandbox.push-apple.com.akadns.net.

Escape character is '^]'.



I tried the openssl s_client connect:


~/Desktop/APNS-PHP $ openssl s_client -connect gateway.sandbox.push.apple.com:2195 -cert aps_combined.pem -key aps_combined.pem

Enter pass phrase for aps_combined.pem:

CONNECTED(00000003)

depth=1 /C=US/O=Entrust, Inc./OU=See www.entrust.net/legal-terms/OU=(c) 2012 Entrust, Inc. - for authorized use only/CN=Entrust Certification Authority - L1K

verify error:num=20:unable to get local issuer certificate

verify return:0

---

Certificate chain

0 s:/C=US/ST=California/L=Cupertino/O=Apple Inc./CN=gateway.sandbox.push.apple.com

i:/C=US/O=Entrust, Inc./OU=See www.entrust.net/legal-terms/OU=(c) 2012 Entrust, Inc. - for authorized use only/CN=Entrust Certification Authority - L1K

1 s:/C=US/O=Entrust, Inc./OU=See www.entrust.net/legal-terms/OU=(c) 2012 Entrust, Inc. - for authorized use only/CN=Entrust Certification Authority - L1K

i:/O=Entrust.net/OU=www.entrust.net/CPS_2048 incorp. by ref. (limits liab.)/OU=(c) 1999 Entrust.net Limited/CN=Entrust.net Certification Authority (2048)

---

Server certificate

-----BEGIN CERTIFICATE-----

MIIFUTCCBDmgAwIBAgIRAP/KN+WwyNu6AAAAAFDYCGYwDQYJKoZIhvcNAQELBQAw

/*Deleted a bunch of lines in the middle here*/

Hke/uLEPEGV/r6N1NSgQqbajUVgqUCrG3GPHsmuVHCFWSP1YYc+2FwKYOLEUgbma

yYBeaZ+LYzqYxyZzBvj+jTaRKi56

-----END CERTIFICATE-----

subject=/C=US/ST=California/L=Cupertino/O=Apple Inc./CN=gateway.sandbox.push.apple.com

issuer=/C=US/O=Entrust, Inc./OU=See www.entrust.net/legal-terms/OU=(c) 2012 Entrust, Inc. - for authorized use only/CN=Entrust Certification Authority - L1K

---

Acceptable client certificate CA names

/C=US/O=Apple Inc./OU=Apple Certification Authority/CN=Apple Root CA

/C=US/O=Apple Inc./OU=Apple Certification Authority/CN=Apple Application Integration Certification Authority

/C=US/O=Apple Inc./OU=Apple Worldwide Developer Relations/CN=Apple Worldwide Developer Relations Certification Authority

/C=US/ST=CA/L=Cupertino/O=Apple Inc./OU=Internet Software and Services/CN=iCloud Test/emailAddress=APNS-Dev@group.apple.com

/CN=Apple Application Integration 2 Certification Authority/OU=Apple Certification Authority/O=Apple Inc./C=US

---

SSL handshake has read 3522 bytes and written 2179 bytes

---

New, TLSv1/SSLv3, Cipher is AES256-SHA

Server public key is 2048 bit

Secure Renegotiation IS supported

Compression: NONE

Expansion: NONE

SSL-Session:

Protocol : TLSv1

Cipher : AES256-SHA

Session-ID:

Session-ID-ctx:

Master-Key: 81E/*deleted a bunch out of this line*/818C9E

Key-Arg : None

Start Time: 1497359153

Timeout : 300 (sec)

Verify return code: 0 (ok)

---

PHP Script to Send Push Notifications.
 
 
Q