【问题标题】:PHP IOS Push Notification ( Permission Denied )PHP IOS 推送通知(权限被拒绝)
【发布时间】:2012-04-04 15:57:47
【问题描述】:

我从昨晚开始就一直在寻找这个问题的答案,但我似乎找不到遇到完全相同问题的人。类似但不是。我正在尝试通过 stream_socket_client 连接到 Apples APNS。我在 LAMP 环境中工作,并打开了 2195 端口。我的 errorString 说 ( Permission denied )。我的麻烦是找到发布了很多关于此错误的信息的人。我从错误报告中得到的警告是 Warning: stream_socket_client(): unable to connect to ssl://gateway.sandbox.push.apple.com:2195 (Permission denied)

至于好东西。我写了一个类来处理这个推送通知。这是设置连接的未完成方法。

 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);

    }

在我看来,这看起来是对的,但很明显,这是不对的。

【问题讨论】:

    标签: php ios apple-push-notifications


    【解决方案1】:

    这是一个 SELinux 会议

    问题出在 Fedora 12 中默认启用的 httpd_can_network_connect SELinux 设置。

    在 shell 控制台中,以 root 身份运行:

    /usr/sbin/setsebool httpd_can_network_connect=1
    

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

    【讨论】:

    • 我目前无法确认这是正确的,因为这个问题已经存在 3 年了。
    【解决方案2】:

    以下教程中的 simplepush.php 代码对我来说效果很好。 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);
    

    【讨论】:

    • 我认为这实际上是openssl的服务器问题。我更改了一些配置,它现在可以工作了。感谢您的提醒。哦,也不要使用 verify_peer 选项。
    • @TimLieberman 您在服务器中所做的更改,请写在这里,以便我也可以检查我的配置。谢谢
    • @Ron 我不记得问题是什么,也不记得我们是如何解决的。很抱歉,当我发现时我应该更新这个问题。
    猜你喜欢
    • 2011-12-24
    • 2013-01-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-10-24
    • 2014-02-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多