尝试通过php文件执行Apple推送通知时出错

I'm working on push notification in IOS with php server and I produced the certificate and keys of the app also I'm ensure from unblocking port for ssl://gateway.sandbox.push.apple.com:2196 and 2195 but at all time I get this error during try to connect on ssl also I'm sure from the permission of all key files

Warning: stream_socket_client(): SSL: crypto enabling timeout in /Users/samahahmaed/Desktop/CER/newspush.php on line 24

Warning: stream_socket_client(): Failed to enable crypto in /Users/samahahmaed/Desktop/CER/newspush.php on line 24

Warning: stream_socket_client(): unable to connect to ssl://gateway.sandbox.push.apple.com:2195 (Unknown error) in /Users/samahahmaed/Desktop/CER/newspush.php on line 24
Failed to connect: 0

Edited:

When I'm trying this command

openssl s_client -connect gateway.sandbox.push.apple.com:2195 -cert PushCertificate.pem -key PushKey.pem -CApath /etc/ssl/certs/Entrust_Root_Certification_Authority.pem

I get this error

CONNECTED(00000003)
write:errno=54

php file:

  <?php

  // Put your device token here (without spaces):
  $deviceToken = 'mydevicetokenhere';

 // Put your private key's passphrase here:
 $passphrase = '1234';

 $message = $argv[1];
 $url = $argv[2];

 if (!$message || !$url)
exit('Example Usage: $php newspush.php \'Breaking News!\'   \'https://raywenderlich.com\'' . "
");



$ctx = stream_context_create();
stream_context_set_option($ctx, 'ssl', 'local_cert',  'apple_push_notification_production.pem');
stream_context_set_option($ctx, 'ssl', 'passphrase', $passphrase);

// Open a connection to the APNS server
  $fp = stream_socket_client(
  'ssl://gateway.sandbox.push.apple.com:2195', $err,
  $errstr, 60, STREAM_CLIENT_CONNECT|STREAM_CLIENT_PERSISTENT, $ctx);

  if (!$fp)
  exit("Failed to connect: $err $errstr" . PHP_EOL);

  echo 'Connected to APNS' . PHP_EOL;

  // Create the payload body
   $body['aps'] = array(
   'alert' => $message,
   'sound' => 'default',
   'link_url' => $url,
  );

  // Encode the payload as JSON
   $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));

 if (!$result)
  echo 'Message not delivered' . PHP_EOL;
 else
  echo 'Message successfully delivered' . PHP_EOL;

 // Close the connection to the server
  fclose($fp);

I searched a lot about this issue and I tried all possible solutions but without any result what I can do now ?

Edited:

After add -debug to openssl command the most strange thing these lines: enter image description here

stream_context_set_option($ctx, 'ssl', 'local_cert',  'apple_push_notification_production.pem');

This line looks like you are using production certificate to connect to sandbox APNS. Try using development certificate. You can get the same from apple developer dashboard.