0

OK, I know there has been a lot of discussion regarding APNS connection failures. Most of the discussion recommends checking the outgoing server port 2195 to be sure it will allow the connection. This is not my problem, although I am experiencing the 'connection refused' error (111).

I have validated communication between my server and the sandbox server be receiving a 200 response from the Apple Gateway. I know my certificates are good because I have tested the connection using openssl from a Mac. I have also been able to connect with the gateway once from my server but cannot get a consistent connection.

The test code I am using is as follows:

$ctx = stream_context_create();

stream_context_set_option($ctx,'ssl', 'local_cert', $pem);
stream_context_set_option($ctx, 'ssl', 'passphrase', $key);
$gateway = 'gateway.sandbox.push.apple.com';
$port = '2195';

$remote_socket = 'ssl://'.$gateway.':'.$port;
$fp = stream_socket_client($remote_socket, $err, $errstr, 60,STREAM_CLIENT_CONNECT, $ctx);

if (!$fp){
    echo $err.'<br>';
    echo $errstr.'</br>';
    echo 'error=apple failed to connect';
} else {
    fclose($fp);
    echo 'success';
}

I have placed the .pem file in the same directory as the script file, removed the use of the passphrase, specified verify_peer, used the STREAM_CLIENT_ASYNC_CONNECT and the STREAM_CLIENT_PERSISTENT flags without success.

Is this an issue with something that I am doing, an issue with the apns sandbox server or is this what I should expect from the apns? Any insights or help you can provide is greatly appreciated -- my hair is getting pretty thin!

Regards.

PS -- If I remove the passphrase I get a 115 error saying the key cannot be accessed.

4

2 回答 2

2

尽管至少可以连接一次,但事实证明,如果没有 GoDaddy 上的虚拟专用服务器,您将无法访问 APNS 网关。每月至少 80 美元,预付,这太贵了。以其他方式。

于 2013-02-08T18:43:58.080 回答
1

其他一些可以尝试的事情:

  1. 在 stream_socket_client 调用中使用STREAM_CLIENT_CONNECT|STREAM_CLIENT_PERSISTENT
  2. 不要使用 verify_peer
  3. 检查 PHP 脚本的所有者是否有足够的权限来读取 pem 文件并连接到位于其他地方的端口(即/不仅仅是本地主机)
于 2013-02-08T13:31:12.647 回答