apns-php
 All Data Structures Files Functions Variables Groups Pages
ApnsPHP_Feedback Class Reference

The Feedback Service client. More...

Inheritance diagram for ApnsPHP_Feedback:
Inheritance graph
Collaboration diagram for ApnsPHP_Feedback:
Collaboration graph

Public Member Functions

array receive ()
 Receives feedback tuples from Apple Push Notification Service feedback. More...
 
- Public Member Functions inherited from ApnsPHP_Abstract
void __construct (integer $nEnvironment, string $sProviderCertificateFile)
 Constructor. More...
 
void connect ()
 Connects to Apple Push Notification service server. More...
 
boolean disconnect ()
 Disconnects from Apple Push Notifications service server. More...
 
string getCertificateAuthority ()
 Get the Root Certification Authority file path. More...
 
integer getConnectRetryInterval ()
 Get the connect retry interval. More...
 
integer getConnectRetryTimes ()
 Get the connect retry time value. More...
 
integer getConnectTimeout ()
 Get the connection timeout. More...
 
ApnsPHP_Log_Interface getLogger ()
 Get the Logger instance. More...
 
integer getSocketSelectTimeout ()
 Get the TCP socket select timeout. More...
 
integer getWriteInterval ()
 Get the write interval. More...
 
void setConnectRetryInterval (integer $nRetryInterval)
 Set the connect retry interval. More...
 
void setConnectRetryTimes (integer $nRetryTimes)
 Set the connect retry times value. More...
 
void setConnectTimeout (integer $nTimeout)
 Set the connection timeout. More...
 
void setLogger (ApnsPHP_Log_Interface $logger)
 Set the Logger instance to use for logging purpose. More...
 
void setProviderCertificatePassphrase (string $sProviderCertificatePassphrase)
 Set the Provider Certificate passphrase. More...
 
void setRootCertificationAuthority (string $sRootCertificationAuthorityFile)
 Set the Root Certification Authority file. More...
 
void setSocketSelectTimeout (integer $nSelectTimeout)
 Set the TCP socket select timeout. More...
 
void setWriteInterval (integer $nWriteInterval)
 Set the write interval. More...
 

Data Fields

const TIME_BINARY_SIZE = 4
 integer Timestamp binary size in bytes. More...
 
const TOKEN_LENGTH_BINARY_SIZE = 2
 integer Token length binary size in bytes. More...
 
- Data Fields inherited from ApnsPHP_Abstract
const CONNECT_RETRY_INTERVAL = 1000000
 integer Default connect retry interval in micro seconds. More...
 
const DEVICE_BINARY_SIZE = 32
 integer Device token length. More...
 
const ENVIRONMENT_PRODUCTION = 0
 integer Production environment. More...
 
const ENVIRONMENT_SANDBOX = 1
 integer Sandbox environment. More...
 
const SOCKET_SELECT_TIMEOUT = 1000000
 integer Default socket select timeout in micro seconds. More...
 
const WRITE_INTERVAL = 10000
 integer Default write interval in micro seconds. More...
 

Protected Member Functions

array _parseBinaryTuple (string $sBinaryTuple)
 Parses binary tuples. More...
 
- Protected Member Functions inherited from ApnsPHP_Abstract
boolean _connect ()
 Connects to Apple Push Notification service server. More...
 
void _log (string $sMessage)
 Logs a message through the Logger. More...
 

Protected Attributes

array $_aFeedback
 Feedback container. More...
 
 $_aServiceURLs
 array Feedback URLs environments. More...
 
- Protected Attributes inherited from ApnsPHP_Abstract
array $_aServiceURLs = array()
 Container for service URLs environments. More...
 
resource $_hSocket
 SSL Socket. More...
 
ApnsPHP_Log_Interface $_logger
 Logger. More...
 
integer $_nConnectRetryInterval
 Connect retry interval in micro seconds. More...
 
integer $_nConnectRetryTimes = 3
 Connect retry times. More...
 
integer $_nConnectTimeout
 Connect timeout in seconds. More...
 
integer $_nEnvironment
 Active environment. More...
 
integer $_nSocketSelectTimeout
 Socket select timeout in micro seconds. More...
 
integer $_nWriteInterval
 Write interval in micro seconds. More...
 
string $_sProviderCertificateFile
 Provider certificate file with key (Bundled PEM). More...
 
string $_sProviderCertificatePassphrase
 Provider certificate passphrase. More...
 
string $_sRootCertificationAuthorityFile
 Root certification authority file. More...
 

Detailed Description

The Feedback Service client.

Apple Push Notification Service includes a feedback service that APNs continually updates with a per-application list of devices for which there were failed-delivery attempts. Providers should periodically query the feedback service to get the list of device tokens for their applications, each of which is identified by its topic. Then, after verifying that the application hasn’t recently been re-registered on the identified devices, a provider should stop sending notifications to these devices.

See Also
http://tinyurl.com/ApplePushNotificationFeedback

Definition at line 39 of file Feedback.php.

Member Function Documentation

array _parseBinaryTuple ( string  $sBinaryTuple)
protected

Parses binary tuples.

Parameters
$sBinaryTupleA binary tuple to parse.
Returns
Array with timestamp, tokenLength and deviceToken keys.

Definition at line 113 of file Feedback.php.

Referenced by receive().

114  {
115  return unpack('Ntimestamp/ntokenLength/H*deviceToken', $sBinaryTuple);
116  }

Here is the caller graph for this function:

array receive ( )

Receives feedback tuples from Apple Push Notification Service feedback.

Every tuple (array) contains:

  • timestamp indicating when the APNs determined that the application no longer exists on the device. This value represents the seconds since 1970, anchored to UTC. You should use the timestamp to determine if the application on the device re-registered with your service since the moment the device token was recorded on the feedback service. If it hasn’t, you should cease sending push notifications to the device.
  • tokenLength The length of the device token (usually 32 bytes).
  • deviceToken The device token.
Returns
Array of feedback tuples (array).

Definition at line 66 of file Feedback.php.

References $_aFeedback, ApnsPHP_Abstract::_log(), and _parseBinaryTuple().

67  {
68  $nFeedbackTupleLen = self::TIME_BINARY_SIZE + self::TOKEN_LENGTH_BINARY_SIZE + self::DEVICE_BINARY_SIZE;
69 
70  $this->_aFeedback = array();
71  $sBuffer = '';
72  while (!feof($this->_hSocket)) {
73  $this->_log('INFO: Reading...');
74  $sBuffer .= $sCurrBuffer = fread($this->_hSocket, 8192);
75  $nCurrBufferLen = strlen($sCurrBuffer);
76  if ($nCurrBufferLen > 0) {
77  $this->_log("INFO: {$nCurrBufferLen} bytes read.");
78  }
79  unset($sCurrBuffer, $nCurrBufferLen);
80 
81  $nBufferLen = strlen($sBuffer);
82  if ($nBufferLen >= $nFeedbackTupleLen) {
83  $nFeedbackTuples = floor($nBufferLen / $nFeedbackTupleLen);
84  for ($i = 0; $i < $nFeedbackTuples; $i++) {
85  $sFeedbackTuple = substr($sBuffer, 0, $nFeedbackTupleLen);
86  $sBuffer = substr($sBuffer, $nFeedbackTupleLen);
87  $this->_aFeedback[] = $aFeedback = $this->_parseBinaryTuple($sFeedbackTuple);
88  $this->_log(sprintf("INFO: New feedback tuple: timestamp=%d (%s), tokenLength=%d, deviceToken=%s.",
89  $aFeedback['timestamp'], date('Y-m-d H:i:s', $aFeedback['timestamp']),
90  $aFeedback['tokenLength'], $aFeedback['deviceToken']
91  ));
92  unset($aFeedback);
93  }
94  }
95 
96  $read = array($this->_hSocket);
97  $null = NULL;
98  $nChangedStreams = stream_select($read, $null, $null, 0, $this->_nSocketSelectTimeout);
99  if ($nChangedStreams === false) {
100  $this->_log('WARNING: Unable to wait for a stream availability.');
101  break;
102  }
103  }
104  return $this->_aFeedback;
105  }
array _parseBinaryTuple(string $sBinaryTuple)
Parses binary tuples.
Definition: Feedback.php:113
void _log(string $sMessage)
Logs a message through the Logger.
Definition: Abstract.php:414
array $_aFeedback
Feedback container.
Definition: Feedback.php:49

Here is the call graph for this function:

Field Documentation

array $_aFeedback
protected

Feedback container.

Definition at line 49 of file Feedback.php.

Referenced by receive().

$_aServiceURLs
protected
Initial value:
= array(
'tls://feedback.push.apple.com:2196',
'tls://feedback.sandbox.push.apple.com:2196'
)

array Feedback URLs environments.

Definition at line 44 of file Feedback.php.

const TIME_BINARY_SIZE = 4

integer Timestamp binary size in bytes.

Definition at line 41 of file Feedback.php.

const TOKEN_LENGTH_BINARY_SIZE = 2

integer Token length binary size in bytes.

Definition at line 42 of file Feedback.php.


The documentation for this class was generated from the following file: