【发布时间】:2017-02-20 11:30:20
【问题描述】:
我的应用程序发送 iOS 通知。我使用fread() 检查Apple 服务器的响应是否有错误。但是,代码会陷入循环或继续加载。
$apnsHost = 'gateway.sandbox.push.apple.com';
$apnsCert = 'j_.pem';
$apnsPort = 2195;
$apnsPass = '';
$notification = "hey";
$streamContext = stream_context_create();
stream_context_set_option($streamContext, 'ssl', 'local_cert', $apnsCert);
stream_context_set_option($streamContext, 'ssl', 'passphrase', $apnsPass);
$apns = stream_socket_client('ssl://'.$apnsHost.':'.$apnsPort, $error, $errorString, 2, STREAM_CLIENT_CONNECT, $streamContext);
$payload['aps'] = array('alert' => $notification, 'sound' => 'default','link'=>'https://google.com','content-available'=>"1");
$output = json_encode($payload);
$token = pack('H*', str_replace(' ', '', "device_token"));
$apnsMessage = chr(0).chr(0).chr(32).$token.chr(0).chr(strlen($output)).$output;
fwrite($apns, $apnsMessage);
$response = fread($apns,6);
fclose($apns);
我做错了什么?
【问题讨论】:
-
你的问题是......
-
我的问题,为什么这个过程没有完成。它一直在处理。
-
我会添加一些调试行来确定它有多远以及它在哪里停止/卡住。当我使用不显示在屏幕上的 PHP 脚本时,我会从脚本中的不同点向自己发送电子邮件,然后我可以更具体地弄清楚发生了什么。