Php 发送APN时连接失败

Php 发送APN时连接失败,php,apple-push-notifications,Php,Apple Push Notifications,我正在使用php发送消息,但它显示了此消息。我必须在apache或iptable上确认任何内容吗 错误:- Failed to connect: 0 php_network_getaddresses: getaddrinfo failed: Name or service not known <?php $device_tokens_array=array(); array_push($device_tokens_array,'8142804172256bd271efb

我正在使用php发送消息,但它显示了此消息。我必须在apache或iptable上确认任何内容吗

错误:-

Failed to connect: 0 php_network_getaddresses: getaddrinfo failed: 
Name or service not known
<?php
    $device_tokens_array=array();
    array_push($device_tokens_array,'8142804172256bd271efba1122d6560f8304e0b7a90a578b0bff138917d233c4');
    array_push($device_tokens_array,'a80c93c67bef026be9affe03689288c08eb1c44f9b6bb5c3d7cc9eb9f9fbf506');


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

    // Put your alert message here:
    $message = 'Hello world';

    ////////////////////////////////////////////////////////////////////////////////

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

    // Open a connection to the APNS server
    $fp = stream_socket_client(
        'ssl://gateway.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'
        );

    $payload = json_encode($body);

      for($i=0; $i<count($device_tokens_array); $i++)
{
    $msg = chr(0) . chr(0) . chr(32) . pack('H*', str_replace(' ', '', $device_tokens_array[$i])) . chr(0) . chr(strlen($payload)) . $payload;
    $result = fwrite($fp, $msg, strlen($msg));
    if (!$result)
        echo '<br>Message not delivered' . PHP_EOL;
    else
        echo '<br>Message successfully delivered' . PHP_EOL;
}

    // Send it to the server


   // Put your device token here (without spaces):


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

   ?>
代码:-

Failed to connect: 0 php_network_getaddresses: getaddrinfo failed: 
Name or service not known
<?php
    $device_tokens_array=array();
    array_push($device_tokens_array,'8142804172256bd271efba1122d6560f8304e0b7a90a578b0bff138917d233c4');
    array_push($device_tokens_array,'a80c93c67bef026be9affe03689288c08eb1c44f9b6bb5c3d7cc9eb9f9fbf506');


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

    // Put your alert message here:
    $message = 'Hello world';

    ////////////////////////////////////////////////////////////////////////////////

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

    // Open a connection to the APNS server
    $fp = stream_socket_client(
        'ssl://gateway.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'
        );

    $payload = json_encode($body);

      for($i=0; $i<count($device_tokens_array); $i++)
{
    $msg = chr(0) . chr(0) . chr(32) . pack('H*', str_replace(' ', '', $device_tokens_array[$i])) . chr(0) . chr(strlen($payload)) . $payload;
    $result = fwrite($fp, $msg, strlen($msg));
    if (!$result)
        echo '<br>Message not delivered' . PHP_EOL;
    else
        echo '<br>Message successfully delivered' . PHP_EOL;
}

    // Send it to the server


   // Put your device token here (without spaces):


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

   ?>