Skip to content

Instantly share code, notes, and snippets.

@cherifya
Created October 23, 2012 00:02
Show Gist options
  • Save cherifya/3935675 to your computer and use it in GitHub Desktop.
Save cherifya/3935675 to your computer and use it in GitHub Desktop.
APNS
/**
* Connects to Apple Push Notification service server.
*
* @throws ApnsPHP_Exception if is unable to connect.
* @return @type boolean True if successful connected.
*/
protected function _connect()
{
$sURL = $this->_aServiceURLs[$this->_nEnvironment];
unset($aURLs);
$this->_log("INFO: Trying {$sURL}...");
/**
* @see http://php.net/manual/en/context.ssl.php
*/
$streamContext = stream_context_create(array('ssl' => array(
'verify_peer' => isset($this->_sRootCertificationAuthorityFile),
'cafile' => $this->_sRootCertificationAuthorityFile,
'local_cert' => $this->_sProviderCertificateFile,
'passphrase' => 'nightspender'
)));
$this->_hSocket = @stream_socket_client($sURL, $nError, $sError,
$this->_nConnectTimeout, STREAM_CLIENT_CONNECT, $streamContext);
if (!$this->_hSocket) {
throw new ApnsPHP_Exception(
"Unable to connect to '{$sURL}': {$sError} ({$nError})"
);
}
stream_set_blocking($this->_hSocket, 0);
stream_set_write_buffer($this->_hSocket, 0);
$this->_log("INFO: Connected to {$sURL}.");
return true;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment