1

I am getting the following errors while connecting the APNS and sending a push notification.

Errors:

Warning: stream_socket_client(): SSL operation failed with code 1. OpenSSL Error messages: error:14090086:SSL routines:ssl3_get_server_certificate:certificate verify failed in /filepath/file.php on line 63

Warning: stream_socket_client(): Failed to enable crypto in /filepath/file.php on line 63

Warning: stream_socket_client(): unable to connect to tls://gateway.push.apple.com:2195 (Unknown error) in /filepath/file.php on line 63

My code is:

$ctx = stream_context_create();    
tream_context_set_option($ctx, 'ssl', 'local_cert', $pemfile);    
stream_context_set_option($ctx, 'ssl', 'passphrase', $passphrase);    
$fp = stream_socket_client(
            'ssl://gateway.push.apple.com:2195',
            $err,
            $errstr,
            60,
            STREAM_CLIENT_CONNECT | STREAM_CLIENT_PERSISTENT,
            $ctx
        );

Seems the .pem file ($pemfile) is not connecting over the SSL.

I am using the PHP Version 7.2.8

Community
  • 1
  • 1
Varun P V
  • 1,092
  • 1
  • 12
  • 30

1 Answers1

2

Finally, I fixed my issue by replacing

$ctx = stream_context_create();

with:

$ctx = stream_context_create([
            'ssl' => [
                'verify_peer'      => false,
                'verify_peer_name' => false
            ]
        ]);
Varun P V
  • 1,092
  • 1
  • 12
  • 30