PHP uses apns feedback Service

Source: Internet
Author: User
Tags autoload ssl certificate

1. the URL is different. The port is 2196.

2. Use the same certificate to establish a secure connection and accept the data until the data does not exist, similar to the table select operation.

3. Each record is a token. The server then deletes these device token records.

Access to the feedback service takes place through a binary interface similar to that used for sending push notifications. you access the production feedback,
Port 2196; you access the sandbox feedback, Port 2196. As with the binary interface for push notifications, you must
Use TLS (or SSL) to establish a secured communications channel. the SSL certificate required for these connections is the same one that is provisioned for sending communications. to establish a trusted provider identity, you shoshould present this certificate
To apns at connection time using peer-to-peer authentication.

Once you are connected, Transmission begins immediately; you do not need to send any command to apns. begin reading the stream written by the feedback service until there is no more data to read. the specified ed data is in tuples having the following format:

5-4 binary format of a feedback tuple


  • Autoload System, Explicitly include only autoload. php and all classes are loaded on-demand.
  • Message class, To build a notification payload.
  • Push class, To push one or more messages to Apple push notification service.
  • Feedback class, To query the apple feedback service to get the list of broken device tokens.
  • Push server class, To create a push server with one or more (forked) processes reading from a common message queue.
  • Log class/interface, To log to standard output or for custom logging purpose.
  • Objective-C Demo projectWithNot-running, Running inForegroundAnd running inBackgroundApplication State support.
Classes hierarchy

Let's take a look at the feedback code:

public function receive(){$nFeedbackTupleLen = self::TIME_BINARY_SIZE + self::TOKEN_LENGTH_BINARY_SIZE + self::DEVICE_BINARY_SIZE;$this->_aFeedback = array();$sBuffer = '';while (!feof($this->_hSocket)) {$this->_log('INFO: Reading...');$sBuffer .= $sCurrBuffer = fread($this->_hSocket, 8192);$nCurrBufferLen = strlen($sCurrBuffer);if ($nCurrBufferLen > 0) {$this->_log("INFO: {$nCurrBufferLen} bytes read.");}unset($sCurrBuffer, $nCurrBufferLen);$nBufferLen = strlen($sBuffer);if ($nBufferLen >= $nFeedbackTupleLen) {$nFeedbackTuples = floor($nBufferLen / $nFeedbackTupleLen);for ($i = 0; $i < $nFeedbackTuples; $i++) {$sFeedbackTuple = substr($sBuffer, 0, $nFeedbackTupleLen);$sBuffer = substr($sBuffer, $nFeedbackTupleLen);$this->_aFeedback[] = $aFeedback = $this->_parseBinaryTuple($sFeedbackTuple);$this->_log(sprintf("INFO: New feedback tuple: timestamp=%d (%s), tokenLength=%d, deviceToken=%s.",$aFeedback['timestamp'], date('Y-m-d H:i:s', $aFeedback['timestamp']),$aFeedback['tokenLength'], $aFeedback['deviceToken']));unset($aFeedback);}}$read = array($this->_hSocket);$null = NULL;$nChangedStreams = stream_select($read, $null, $null, 0, $this->_nSocketSelectTimeout);if ($nChangedStreams === false) {$this->_log('WARNING: Unable to wait for a stream availability.');break;}}return $this->_aFeedback;}/** * Parses binary tuples. * * @param  $sBinaryTuple @type string A binary tuple to parse. * @return @type array Array with timestamp, tokenLength and deviceToken keys. */protected function _parseBinaryTuple($sBinaryTuple){return unpack('Ntimestamp/ntokenLength/H*deviceToken', $sBinaryTuple);}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.