PHP to do iOS push server, the background will be running when the two messages are pushed? Have code

Source: Internet
Author: User
Keywords Php
Php

Why does PHP push two messages when it is running in the background when the server is pushed by iOS? But the mobile phone off the screen push the time is normal ~ Only the background to run the time is two?? How to change it?
Here is the code

 /** Mobile phone push information class @author:wtt*/class push{private $deviceToken;    Private $message;         function __construct ($deviceToken, $message) {$this->devicetoken = $deviceToken;     $this->message = $message;             } public Function push () {//CK.PEM customs password $pass = ' 123456 ';          Message content//badge I don't know what it is $badge = 1;          Sound I don't know what it is (perhaps the cue tone when the message is pushed to the phone) $sound = ' duck.wav ';          Construction notification Payload (i.e. some information contained in the notification) $body = array ();          $body [' aps '] = Array (' alert ' = = $this->message);          if ($badge) $body [' APs '] [' badge '] = $badge;          if ($sound) $body [' APs '] [' sound '] = $sound;          Convert array data to JSON data $payload = Json_encode ($body);           echo strlen ($payload), "\ r \ n"; The following writing is the death of the wording, generally do not need to modify,//The only thing to modify is: ssl://gateway.sandbox.push.apple.com:2195 This is the sandbox test address, ssl://          GATEWAY.PUSH.APPLE.COM:2195 official release Address $ctx = Stream_context_create (); Stream_context_set_option ($ctx, ' SSL ', ' Local_cert ', ' Ck.pem ');          Stream_context_set_option ($ctx, ' SSL ', ' passphrase ', $pass); $fp = stream_socket_client (' ssl://gateway.sandbox.push.apple.com:2195 ', $err, $errstr, $, stream_client_connect, $          CTX);              if (! $fp) {print "Failed to connect {$err} {$errstr}\n";          Return } else {//print "Connection ok\n
"; }//Send Message $msg = Chr (0). Pack ("n", 32). Pack (' h* ', Str_replace (', ', $this->devicetoken)). Pack ("n", strlen ($payload)). $payload; Print "Sending message:". $payload. "\ n"; Fwrite ($fp, $msg); Fclose ($FP); }}
  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.