Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

stream_socket_client failing on my server with no way to know more about the error

This code: (https://github.com/stuffmc/Safari-Push-Notifications/blob/master/index.php#L195)

stream_socket_client('ssl://gateway.push.apple.com:2195', $error, $errorString, 
                      60, STREAM_CLIENT_CONNECT, $streamContext);

returns false, but with no errors. It means that when I'm sending to /v1/push it fails for every device/token :( The PHP documentation says:

If the value returned in errno is 0 and the function returned FALSE, it is an indication that the error occurred before the connect() call. This is most likely due to a problem initializing the socket.

I have this code running perfectly for a website (dev/beta/staging) and now that I'm trying to move to production, it doesn't.

I should note though that calling

$ openssl s_client -connect gateway.push.apple.com:2195 -cert MyC.pem -key myK.pem

perfectly works. I have a prompt where I can type characters and when typing enter, it exits — same as with my dev test.

I also have nothing sent to /v1/log (as mentionned at https://devforums.apple.com/thread/203825) and so I'm clueless as to where the problem would be :(

like image 635
StuFF mc Avatar asked Oct 01 '22 06:10

StuFF mc


1 Answers

I fixed my problem by generating the .pem this way:

openssl pkcs12 -in key-chain-export.p12 -out apple_push_cert_production.pem -nodes -clcerts

I still would love to know how I could have had a "hint" (from PHP or openssl) that it's the certificate.

AND: Although it fixed the problem on the server side, I then got problems on the client side. Oh well.....

I should also mention I fixed the code on the server so that /v1/log gets something from Apple.

See https://github.com/surrealroad/Safari-Push-Notifications/commit/0ae8a3ad3327a957c332090ea1bfcb146a40c5f3

like image 109
StuFF mc Avatar answered Oct 12 '22 23:10

StuFF mc