1
[Tue Feb 05 00:16:13 2013] [error] [client 112.11.122.37] PHP Warning:  stream_socket_client(): unable to connect to ssl://17.149.38.141:2195 (Connection timed out) in /chroot/updateapp_push.php on line 72 
[Tue Feb 05 00:16:13 2013] [error] [client 112.11.122.37] PHP Warning:  fwrite() expects parameter 1 to be resource, boolean given in /chroot/updateapp_push.php on line 87
[Tue Feb 05 00:16:13 2013] [error] [client 112.11.122.37] PHP Warning:  fclose() expects parameter 1 to be resource, boolean given in /chroot/updateapp_push.php on line 90

I am getting above error in sending push notification to multiple devices more than 3000 devices. Any suggestion to handle it?

CODE which is in Loop for the number of tokens:

// Passphrase for the private key (ck.pem file)

$pass = 'push';

// Get the parameters from http get or from command line

        $message = 'Application(s) update available';
        //$badge = (int)$_GET['badge'] or $badge = (int)$argv[2];
        $badge = $count_update;
        //$sound = $_GET['sound'] or $sound = $argv[3];

// Construct the notification payload

                $body = array();
                $body['aps'] = array('alert' => $message);
                if ($badge)
                    $body['aps']['badge'] = $badge;

                /* End of Configurable Items */

                $payload = json_encode($body);
                $ctx = stream_context_create();
                stream_context_set_option($ctx, 'ssl', 'local_cert', 'ckappmart.pem');

// assume the private key passphase was removed.

                stream_context_set_option($ctx, 'ssl', 'passphrase', $pass);
                $fp = stream_socket_client('ssl://17.172.238.221:2195', $err, $errstr, 60, STREAM_CLIENT_CONNECT, $ctx);

                if (!$fp) {
                    //print "Failed to connect $err $errstrn";
                }
                else {
                    //print "Connection OKn";
                }

                if($num_getNonMdmPushToken!=0) {
                    for($count=0;$count<1;$count++) {
                        $msg = chr(0) . pack("n",32) . pack('H*', str_replace(' ', '', $deviceToken[$count])) . pack("n",strlen($payload)) . $payload;
                        //print "sending message :" . $payload . "n";
                        fwrite($fp, $msg);
                    }
                }
                fclose($fp);
Varun
  • 111
  • 1
  • 3
  • 9
  • You need to keep the socket connection alive. This could help: http://stackoverflow.com/questions/242316/how-to-keep-a-php-stream-socket-alive – Luke Feb 05 '13 at 00:44

0 Answers0