Tim Lieberman
Tim Lieberman

Reputation: 571

PHP IOS Push Notification ( Permission Denied )

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.

Upvotes: 0

Views: 2403

Answers (2)

davidex
davidex

Reputation: 31

It's a SELinux Conf

The problem turned out to be the httpd_can_network_connect SELinux setting that is on by default in Fedora 12.

In a shell console, run as root:

/usr/sbin/setsebool httpd_can_network_connect=1

reference: http://www.rkrishardy.com/2009/12/permission-denied-13-when-opening-socket-in-php-apache/

Upvotes: 3

roger
roger

Reputation: 33

The simplepush.php code in the following tutorial worked well for me. http://www.raywenderlich.com/3443/apple-push-notification-services-tutorial-part-12

$ctx = stream_context_create();
stream_context_set_option($ctx, 'ssl', 'local_cert', 'ck.pem');
stream_context_set_option($ctx, 'ssl', 'passphrase', $passphrase);

// Open a connection to the APNS server
$fp = stream_socket_client(
    'ssl://gateway.sandbox.push.apple.com:2195', $err,
    $errstr, 60, STREAM_CLIENT_CONNECT|STREAM_CLIENT_PERSISTENT, $ctx);

Upvotes: 0

Related Questions