private function openConnectionAPNS($ctx)
    {
        $fp = false;

        // Open a connection to the APNS server
        try {
            $fp = stream_socket_client(
                $this->url,
                $err,
                $errstr,
                60,
                STREAM_CLIENT_CONNECT|STREAM_CLIENT_PERSISTENT,
                $ctx
            );

            stream_set_blocking($fp, 0);

            if (!$fp) {
                $response = ['success' => false, 'error' => "Failed to connect: $err $errstr" . PHP_EOL];

                $this->setFeedback(json_decode(json_encode($response)));

            }

        } catch (\Exception $e) {
            //if stream socket can't be established, try again
            if ($this->canRetry()) {
                return $this->openConnectionAPNS($ctx);
            }

            $response = ['success' => false, 'error' => 'Connection problem: ' . $e->getMessage() . PHP_EOL];
            $this->setFeedback(json_decode(json_encode($response)));

        } finally {
            $this->resetAttempts();
            return $fp;
        }
    }