Greetings everyone! I'm currently implementing the Feedback service for Apples Push notifications. I've got the pushing part all done and working both on sandbox and on distribution apps. However the feedback service seems to not work.. Each time i try to use my function.. the page well.. just gets a timeout.
I followed this answer to make my function : PHP technique to query the APNs Feedback Server
Here is my full function code :
function checkFeedbackServer($appBundle,$useDev = TRUE)
{
$apnsPort = 2195;
$apnsCert = keyForApp($appBundle,$useDev);
if($useDev)
{
echo 'FEEDBACK in DEVELOPER MODE <br/>';
$apnsHost = 'feedback.sandbox.push.apple.com';
}
else
{
echo 'FEEDBACK in DISTRIBUTION MODE <br/>';
$apnsHost = 'feedback.push.apple.com';
}
$finalPath = 'ssl://' . $apnsHost . ':' . $apnsPort;
echo 'OPENING STREAM TO -> ' . $finalPath . '<br/>';
echo 'USING CERT : ' . $apnsCert . "<br/>";
$stream_context = stream_context_create();
stream_context_set_option($stream_context, 'ssl', 'local_cert', $apnsCert);
$apns = stream_socket_client($finalPath, $error, $errorString, 2, STREAM_CLIENT_CONNECT, $stream_context);
if(!$apns)
{
echo "ERROR $errcode: $errstr\n";
return;
}
else echo 'APNS FEEDBACK CONNECTION ESTABLISHED...<br/>';
$feedback_tokens = array();
$count = 0;
echo 'error= ' . $error . '<br/>';
echo 'errorString= ' . $errorString . '<br/>';
if(!feof($apns))
echo 'APNS NOT FINISHED <br/>';
else
echo 'APNS FINISHED? <br/>';
$result = fread($apns, 38);
echo 'result= ' . $result;
fclose($apns);
}
I noticed that if i remove the lines :
$result = fread($apns, 38);
echo 'result= ' . $result;
The function then works properly. So in a nuthsell I am able to open a connection to the feedback service both production and developer but as soon as I try to get any data from the server my script just times out..
also the function keyForApp($appBundle,$useDev)
is just a simple wrapper around a query to my database that fetches the correct certificate. I guarante it works since I am also using it while pushing messages to the device.
Solved it.. Turns out I had the wrong port. To clarify :
my bad..;) I mixed the two together and was connecting to the feedback server on port 2195 instead of 2196