Warning: stream_socket_client(): unable to connect to ssl://feedback.push.apple.com:2196 (Operation timed out)

On same server feedback is not working and push-notification is working

‘ssl://gateway.push.apple.com:2195 work fine on same server’

I use below code for apns feedback service.

$apnsHost = 'feedback.push.apple.com';
        $apnsPort = 2196;
        if(realpath(dirname(__FILE__)."/../".$customer_id.".pem")){
            $apnsCert = realpath(dirname(__FILE__)."/../".$customer_id.".pem");
        }else{
            $apnsCert = realpath(dirname(__FILE__)."/../ck.pem");
        }
        $ctx = stream_context_create();
        $options = array('ssl' => array(
            'local_cert' =>$apnsCert,
            'passphrase' => '1234'
        ));

        stream_context_set_option($ctx, $options);
        $fp = stream_socket_client('ssl://' . $apnsHost . ':' . $apnsPort, $error, $errorString, 2, STREAM_CLIENT_CONNECT, $ctx);
        // production server is ssl://feedback.push.apple.com:2196

        if (!$fp) {
            error_log("Failed to connect feedback server: $err $errstr",0);
            return;
        }
        else {
            error_log("Connection to feedback server OK",0);
        }
        error_log("APNS feedback results",0);

        while (!feof($fp)) {
            $devcon = fread($fp, 38);
            if(strlen($devcon)) {
                $arr = unpack("H*", $devcon);
                $rawhex = trim(implode("", $arr));
                $feedbackTime = hexdec(substr($rawhex, 0, 8));
                $feedbackDate = date('Y-m-d H:i', $feedbackTime);
                $feedbackLen = hexdec(substr($rawhex, 8, 4));
                $feedbackDeviceToken = substr($rawhex, 12, 64);

                error_log ("TIMESTAMP:" . $feedbackDate, 0);
                error_log ( "DEVICE ID:" . $feedbackDeviceToken,0);
                $logText .= "\nDate : ".$feedbackDate.", DeviceToken:".$feedbackDeviceToken.", Error: ".$ex->getMessage();
            }
        }   
    fclose($fp);
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s