Linode Forum
Linode Community Forums
 FAQFAQ    SearchSearch    MembersMembers      Register Register 
 LoginLogin [ Anonymous ] 
Post new topic  Reply to topic
Author Message
PostPosted: Wed Oct 13, 2010 4:44 pm 
Offline
Newbie

Joined: Wed Oct 13, 2010 12:27 am
Posts: 4
Hello,

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:
<?php
$fp = fsockopen("ssl://gateway.push.apple.com:2195",2195, $errno, $errstr, 30);
if (!$fp) {
echo "Err.$errstr ($errno)<br />\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.


Top
   
 Post subject:
PostPosted: Wed Oct 13, 2010 4:55 pm 
Offline
Junior Member

Joined: Tue Jul 13, 2010 8:28 pm
Posts: 28
More helpful would be the error number and error message verbatim.
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.


Top
   
 Post subject:
PostPosted: Wed Oct 13, 2010 5:38 pm 
Offline
Newbie

Joined: Wed Oct 13, 2010 12:27 am
Posts: 4
This will give the PHP info: http://173.255.209.254/test1.php

Here is the original push notification code

$ctx = stream_context_create();
stream_context_set_option($ctx, 'ssl', 'apns_dev', '.pem');
// assume the private key passphase was removed.
stream_context_set_option($ctx, 'ssl', 'passphrase', $pass);

$fp = stream_socket_client('ssl://gateway.push.apple.com:2195', $err, $errstr,30, STREAM_CLIENT_CONNECT, $ctx);

if (!$fp) {
print "Failed to connect $err $errstr\n";
return;
}
else {
print "Connection OK\n";
}

I always get Failed to connect 0


Top
   
 Post subject:
PostPosted: Wed Oct 13, 2010 7:05 pm 
Offline
Senior Member

Joined: Thu Jul 22, 2010 8:23 pm
Posts: 60
This might help..

$apnsHost = 'gateway.sandbox.push.apple.com';
$apnsPort = 2195;
$apnsCert = 'apns-dev.pem';

$streamContext = stream_context_create();
stream_context_set_option($streamContext, 'ssl', 'local_cert', $apnsCert);

$apns = stream_socket_client('ssl://' . $apnsHost . ':' . $apnsPort, $error, $errorString, 2, STREAM_CLIENT_CONNECT, $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);


Top
   
Display posts from previous:  Sort by  
Post new topic  Reply to topic


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  
RSS

Powered by phpBB® Forum Software © phpBB Group