简体   繁体   中英

getting error in php stream_socket_client(): unable to connect to ssl://gateway.sandbox.push.apple.com:2195 (Connection refused)

I am trying to send notification using apns. I was making a function in php to send message. I am getting en error "stream_socket_client(): unable to connect to ssl://gateway.sandbox.push.apple.com:2195 (Connection refused)" . this code is work fine on my local server. But when i checked on liver server getting error. below is the code

$this->set_url();
$ctx = stream_context_create();
stream_context_set_option($ctx, 'ssl', 'local_cert', $this->pem_file);
stream_context_set_option($ctx, 'ssl', 'passphrase', '1');

$fp = stream_socket_client($this->get_url(), $err, $errstr, 60, STREAM_CLIENT_CONNECT | STREAM_CLIENT_PERSISTENT, $ctx);
$sound = 'default';
$badge = 0;
$body = $this->get_message();
$data['key'] = $body['key'];
$data['sound'] = $sound;
$data['badge'] = $badge + 1;
$data['alert'] = $body['message'];
if (isset($body['extra']))
   $data['extra'] = $body['extra'];
   $apn_data['aps'] = $data;
   $payload = json_encode($apn_data);
   $msg = chr(0) . pack('n', 32) . pack('H*', $this->get_device()) .    pack('n', strlen($payload)) . $payload;
   $result = fwrite($fp, $msg, strlen($msg));
   fclose($fp);

Ask you Server administrator to open port 2195 for outgoing connections. It will solve you issue.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM