Setting up a Push Notifications Server
Has anyone set up a Push Notifications server in the Ubuntu configuration? I could use some help in getting this established since I am trying to get this service started. I'm running some PHP scripts and it returns an error string when it tries to connect.
This is the code snippet:
$fp = fsockopen("ssl://gateway.push.apple.com:2195",2195, $errno, $errstr, 30);
if (!$fp) {
echo "Err.$errstr ($errno)
\n";
} else {
echo "success";/*
$out = "GET / HTTP/1.1\r\n";
$out .= "Host: www.example.com\r\n";
$out .= "Connection: Close\r\n\r\n";
fwrite($fp, $out);
while (!feof($fp)) {
echo fgets($fp, 128);
}*/
fclose($fp);
}
?>
Any detailed solutions would be greatly appreciated. We can discuss a short-term contract if there is much more that is involved. Thanks in advance.
3 Replies
Things like the version of php and distro are also helpful, as might phpinfo() output.
Also, you probably don't need the port in the hostname, since fsockopen expects a port in the function arguments.
Here is the original push notification code
$ctx = streamcontextcreate();
streamcontextsetoption($ctx, 'ssl', 'apnsdev', '.pem');
// assume the private key passphase was removed.
streamcontextset_option($ctx, 'ssl', 'passphrase', $pass);
$fp = streamsocketclient('ssl://gateway.push.apple.com:2195', $err, $errstr,30, STREAMCLIENTCONNECT, $ctx);
if (!$fp) {
print "Failed to connect $err $errstr\n";
return;
}
else {
print "Connection OK\n";
}
I always get Failed to connect 0
$apnsHost = 'gateway.sandbox.push.apple.com';
$apnsPort = 2195;
$apnsCert = 'apns-dev.pem';
$streamContext = streamcontextcreate();
streamcontextsetoption($streamContext, 'ssl', 'localcert', $apnsCert);
$apns = streamsocketclient('ssl://' . $apnsHost . ':' . $apnsPort, $error, $errorString, 2, STREAMCLIENTCONNECT, $streamContext);
//send payload
$apnsMessage = chr(0) . chr(0) . chr(32) . pack('H*', str_replace(' ', '', $deviceToken)) . chr(0) . chr(strlen($payload)) . $payload;
fwrite($apns, $apnsMessage);
//close socket
socket_close($apns);
fclose($apns);