How can I do an SSL connection with PHP

Posted by Anth0 on Stack Overflow See other posts from Stack Overflow or by Anth0
Published on 2010-06-08T13:46:54Z Indexed on 2010/06/09 8:02 UTC
Read the original article Hit count: 287

Filed under:
|
|
|

Hi,

I need to develop a PHP class to communicate with Apple servers in order to do Push notification (APNS). I have the certificate (.pem) and I tried to follow various tutorials found on Internet but I'm still getting error trying to connect to ssl://gateway.sandbox.push.apple.com:2195 with stream socket :

$apnsHost = 'gateway.sandbox.push.apple.com';
$apnsPort = 2195;
$apnsCert = 'apns-dev.pem';
$streamContext = stream_context_create();
stream_context_set_option($streamContext, 'ssl', 'local_cert', $apnsCert);
$apns = stream_socket_client('ssl://'.$apnsHost.':'.$apnsPort, $error, $errorString, 2,
STREAM_CLIENT_CONNECT, $streamContext);

A telnet on this URL works so port 2195 is opened. Openssl is activated on PHP since I get "Registered Stream Socket Transports : tcp, udp, ssl, sslv3, sslv2, tls" with a phpinfo(). My certificate is well read (PHP is_readable(certif.pem) returns true on the file)

Is there anything else to activate in Apache or PHP to get it work ?

© Stack Overflow or respective owner

Related posts about php

Related posts about apache