I've been looking since last night for an answer to this but it seemed I couldn't find anyone that was having the exact same problem. Similar but not it. I'm trying to connect to Apples APNS through a stream_socket_client. I'm working this in a LAMP environment and have port 2195 open. My errorString says ( Permission denied ). My trouble is finding people who've posted much of anything about this error. The warning I'm getting from the error reporting is Warning: stream_socket_client(): unable to connect to ssl://gateway.sandbox.push.apple.com:2195 (Permission denied)
As for the good stuff. I wrote a class to handle this push notification. Here's the unfinshed method to set the connection.
public function setConnection() {
$apnsHost = 'gateway.sandbox.push.apple.com';
$apnsPort = 2195;
$apnsCert = '../model/apns-dev.pem';
$streamContext = stream_context_create();
stream_context_set_option($streamContext, 'ssl', 'local_cert', $apnsCert);
stream_context_set_option($streamContext, 'ssl', 'passphrase', "********");
stream_context_set_option($streamContext, 'ssl', 'verify_peer', true);
$apns = stream_socket_client('ssl://'.$apnsHost.':'. $apnsPort, $error, $errorString, 20, STREAM_CLIENT_CONNECT , $streamContext);
}
To me this looks right but obviously, something that's not right.