ios — Как управлять ошибкой отправки ответа, отправляющей push в APNS из переполнения стека

У меня возникли некоторые проблемы с моей реализацией, потому что она зависала случайным образом после 400 — 500 отправок.

Мне было интересно, почему лучшие учебники APNS для PHP и других платформ советуют вам немного поспать (o много!) После отправки некоторых сообщений на сервер APNS.

Зачем спать ваш код при отправке iOS Push-уведомлений?

Я получаю аварию

<html><head><title>500 Internal Server Error</title></head><body>
<h1>Internal Server Error</h1>
<p><i>stream_socket_client(): php_network_getaddresses: getaddrinfo failed: nodename nor servname provided, or not known</i></p>
<p>#0 /Users/MyUser/development/projects/project/project-api/helpers/PushNotificationHelper.php:407 stream_socket_client('ssl://gateway.sandbox.push.apple.com:2195',0,'',60,5,NULL)<br />...

Мой исходный код:

static function pushIOS($ios_devices, $push_type, $data_array){

$log = new Logger('PushConsumer');
$log->pushHandler(new StreamHandler(BASEPATH.'log/push.log', Logger::DEBUG));

// set time limit to zero in order to avoid timeout
set_time_limit(0);

// this is the pass phrase you defined when creating the key
$passphrase = 'mypass';

// load your device ids to an array
$deviceIds = $ios_devices;

// this is where you can customize your notification
//payload = '{"aps":{"alert":"' . $message . '","sound":"default"}}';
$msg = array
(
'type'          => $push_type,
'message'       => $data_array,
);
$payload = json_encode($msg);
$result = 'Start' . '<br />';

////////////////////////////////////////////////////////////////////////////////
// start to create connection
$ctx = stream_context_create();
stream_context_set_option($ctx, 'ssl', 'local_cert', BASEPATH.'scripts/certificates/appleck.pem');
stream_context_set_option($ctx, 'ssl', 'passphrase', $passphrase);

$log->addDebug(count($deviceIds)." devices will receive notifications.'");
//echo count($deviceIds) . ' devices will receive notifications.<br />';

// Open a connection to the APNS server
$fp = stream_socket_client(F3::get('apns_url'), $err, $errstr, 60, STREAM_CLIENT_CONNECT | STREAM_CLIENT_PERSISTENT, $ctx);

if (!$fp) {
$log->addDebug("Failed to connect: $err $errstr");
exit("Failed to connect: $err $errstr" . '<br />');
} else {
$log->addDebug("Apple service is online.");

foreach ($deviceIds as $item) {

// Build the binary notification
$msg = chr(0) . pack('n', 32) . pack('H*', $item) . pack('n', strlen($payload)) . $payload;

// Send it to the server
$result = fwrite($fp, $msg, strlen($msg));

if (!$result) {
$log->addDebug("Undelivered message to push token: $item");
//echo 'Undelivered message count: ' . $item . '<br />';
} else {
$log->addDebug("Delivered message to push token: $item");
//echo 'Delivered message count: ' . $item . '<br />';
}

}fclose($fp);
$log->addDebug("The connection has been closed by the client");

}

$log->addDebug(count($deviceIds)." devices have received notifications");

// wait for some time
sleep(2);
}

Строка с аварией:

$fp = stream_socket_client(F3::get('apns_url'), $err, $errstr, 60, STREAM_CLIENT_CONNECT | STREAM_CLIENT_PERSISTENT, $ctx);

1

Решение

Задача ещё не решена.

Другие решения

Других решений пока нет …

По вопросам рекламы ammmcru@yandex.ru
Adblock
detector