5

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.

Community
  • 1
  • 1
Toolism
  • 143
  • 1
  • 9

1 Answers1

6

Solved it.. Turns out I had the wrong port. To clarify :

  1. port 2195 is for pushing messages
  2. port 2196 is for getting feedback

my bad..;) I mixed the two together and was connecting to the feedback server on port 2195 instead of 2196

Toolism
  • 143
  • 1
  • 9
  • @TiagoAmaral - did you ever confirm if this worked for ios 8? can you show me the solution you used for using the feedback service? – tamak Mar 10 '15 at 04:49
  • 1
    @tamak i will post the script i make... Is important make a interval of 5 seconts betewen fire push... –  Mar 10 '15 at 04:52
  • @TiagoAmaral Thank you Tiago, the 5 seconds delay will work fine for my needs. – tamak Mar 11 '15 at 04:39
  • 1
    @tamak i make this code> https://github.com/tiagoMaua/Simple-PHP-Push-Server/blob/master/push.php –  Mar 11 '15 at 17:10