Skip to content

Commit

Permalink
New time interval after each socket write.
Browse files Browse the repository at this point in the history
After each socket write operation now we are sleeping for a time interval. The default time interval is 10ms. To speed up the sending operations, use Zero as parameter but some messages may be lost (closes #2).
  • Loading branch information
duccio committed Oct 30, 2012
1 parent fdf58c0 commit d352b53
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 0 deletions.
27 changes: 27 additions & 0 deletions ApnsPHP/Abstract.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ abstract class ApnsPHP_Abstract

const DEVICE_BINARY_SIZE = 32; /**< @type integer Device token length. */

const WRITE_INTERVAL = 10000; /**< @type integer Default write interval in micro seconds. */
const CONNECT_RETRY_INTERVAL = 1000000; /**< @type integer Default connect retry interval in micro seconds. */
const SOCKET_SELECT_TIMEOUT = 1000000; /**< @type integer Default socket select timeout in micro seconds. */

Expand All @@ -58,6 +59,7 @@ abstract class ApnsPHP_Abstract
protected $_sProviderCertificatePassphrase; /**< @type string Provider certificate passphrase. */
protected $_sRootCertificationAuthorityFile; /**< @type string Root certification authority file. */

protected $_nWriteInterval; /**< @type integer Write interval in micro seconds. */
protected $_nConnectRetryInterval; /**< @type integer Connect retry interval in micro seconds. */
protected $_nSocketSelectTimeout; /**< @type integer Socket select timeout in micro seconds. */

Expand Down Expand Up @@ -91,6 +93,7 @@ public function __construct($nEnvironment, $sProviderCertificateFile)
$this->_sProviderCertificateFile = $sProviderCertificateFile;

$this->_nConnectTimeout = ini_get("default_socket_timeout");
$this->_nWriteInterval = self::WRITE_INTERVAL;
$this->_nConnectRetryInterval = self::CONNECT_RETRY_INTERVAL;
$this->_nSocketSelectTimeout = self::SOCKET_SELECT_TIMEOUT;
}
Expand Down Expand Up @@ -184,6 +187,30 @@ public function getCertificateAuthority()
return $this->_sRootCertificationAuthorityFile;
}

/**
* Set the write interval.
*
* After each socket write operation we are sleeping for this
* time interval. To speed up the sending operations, use Zero
* as parameter but some messages may be lost.
*
* @param $nWriteInterval @type integer Write interval in micro seconds.
*/
public function setWriteInterval($nWriteInterval)
{
$this->_nWriteInterval = (int)$nWriteInterval;
}

/**
* Get the write interval.
*
* @return @type integer Write interval in micro seconds.
*/
public function getWriteInterval()
{
return $this->_nWriteInterval;
}

/**
* Set the connection timeout.
*
Expand Down
1 change: 1 addition & 0 deletions ApnsPHP/Push.php
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ public function send()
)
);
}
usleep($this->_nWriteInterval);

$bError = $this->_updateQueue($aErrorMessage);
if ($bError) {
Expand Down
6 changes: 6 additions & 0 deletions sample_push_many.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,12 @@
// Set the Root Certificate Autority to verify the Apple remote peer
$push->setRootCertificationAuthority('entrust_root_certification_authority.pem');

// Increase write interval to 100ms (default value is 10ms).
// This is an example value, the 10ms default value is OK in most cases.
// To speed up the sending operations, use Zero as parameter but
// some messages may be lost.
// $push->setWriteInterval(100 * 1000);

// Connect to the Apple Push Notification Service
$push->connect();

Expand Down

0 comments on commit d352b53

Please sign in to comment.