Try this:
$streamContext = stream_context_create();
stream_context_set_option($streamContext, 'ssl', 'local_cert', $this->sslPem);
stream_context_set_option($streamContext, 'ssl', 'passphrase', $this->passPhrase);
$this->apnsConnection = stream_socket_client('ssl://'.$this->apnsHost.':'.$this->apnsPort, $error, $errorString, 60, STREAM_CLIENT_CONNECT, $streamContext);
$is_keepalive = 0;
$socket = socket_import_stream($this->apnsConnection);
if (socket_set_option($socket, SOL_SOCKET, SO_KEEPALIVE, 1)) {
$is_keepalive = socket_get_option($socket, SOL_SOCKET, SO_KEEPALIVE);
} else {
echo 'Unable to set option on socket: '. socket_strerror(socket_last_error()) . PHP_EOL;
}
if ($is_keepalive) {
$this->apnsConnection = socket_export_stream($socket);
}
Jonny source
share