Warning: stream_socket_client(): unable to connect to ssl://gateway.push.apple.com:2195 (Connection timed out)
When I try to make a push from my local server, it is working fine. But when I am trying the same from external server, I am getting the warning. I am using php and apache.
"Warning: stream_socket_client(): unable to connect to ssl://gateway.push.apple.com:2195 (Connection timed out)".
Below are the configuration in my apache server.The same is iin my local server.But I can not understand why it is always showing me the warning for external server.
OpenSSL support | enabled |
OpenSSL Library Version | OpenSSL 1.0.1e-fips 11 Feb 2013 |
OpenSSL Header Version | OpenSSL 1.0.1e-fips 11 Feb 2013 |
Below are my code in php
_________________________
ini_set("max_execution_time","6000");
//ini_set("max_input_time","1000");
ini_set("default_socket_timeout", 6000);
get_device_token();
function get_device_token(){
$_GET['token'] = 'cc706d069568493f6504186ec5784435284f3625fdba2f69f698a00f9d1526fb'; //Namrata's device old
if(!empty($_GET['token'])){
$deviceToken = $_GET['token'];
//$deviceToken = 'ebf46d5cc1b2f7c34b5a53c1c64c09fbd2e6af8ecffa665a6453e72b24315e0d'; // Namrata's device new
//echo $deviceToken;
$message = "This is new push test-from local";
$res=send_ios_notification($deviceToken, $message);
echo $res;
}else{
echo "No device token";
exit;
}
}
function send_ios_notification($deviceToken, $message){
echo "token : ".$deviceToken." message : ".$message."<BR>";
error_reporting(E_ALL);
ini_set('display_errors', 1);
### push to ipad ###
$passphrase = "123456";
$options = array(
'http'=>array(
'method'=>"GET",
'header'=>"Accept-language: en\r\n",
'timeout' => 60000
)
);
$ctx = stream_context_create();
stream_context_set_option($ctx, 'ssl', 'local_cert', 'push_notification/Push_Certs/ck.pem');
stream_context_set_option($ctx, 'ssl', 'passphrase', $passphrase);
//stream_set_timeout ( $ctx , 600);
$fp = stream_socket_client(
'ssl://gateway.push.apple.com:2195', $err,
$errstr, 60000, STREAM_CLIENT_CONNECT|STREAM_CLIENT_PERSISTENT, $ctx);
echo "error : ".socket_strerror(socket_last_error());
var_dump( $fp );
//stream_set_timeout ( $ctx , 60000);
if (!$fp)
exit("Failed to connect: $err $errstr" . PHP_EOL);
echo 'Connected to APNS' . PHP_EOL;
// Create the payload body
$body['aps'] = array(
'badge' => +1,
'alert' => $message,
'sound' => 'default'
);
$payload = json_encode($body);
// Build the binary notification
$msg = chr(0) . pack('n', 32) . pack('H*', $deviceToken) . pack('n', strlen($payload)) . $payload;
// Send it to the server
$result = fwrite($fp, $msg, strlen($msg));
var_dump( $result );
//print_r( $result );die;
fclose($fp);
die("end");
return $result;
}
Please suggest some solutions.I badly need it.
iOS 7.1