How to use PHP code to implement the push information function of multiple devices such as iOS?
How to implement the push information function of iOS and other devices with PHP code?
It is possible that 6.1 million of terminal devices need to receive push messages, execute once, and enable multiple devices to receive information.
Pass by to give some useful advice, thank you!!! PHP iOS Terminal
Share to:
------Solution--------------------
This is not possible with PHP.
It is certainly not recommended that long connections remain attached until a message is returned to the user, so the server pressure must be great.
It is recommended to use the heartbeat to achieve this function, the client browser timed to the server to get the latest news.
In addition, if not PHP, such as Python, Nodejs, C + + and other implementation of the background, you can use long polling.
------Solution--------------------
This is not what PHP can do!
PHP is a server-side script, not a server, not a network operating system
You just need to apply the mobile communications operating system to achieve your goals
------Solution--------------------
You want the source code to go to the mobile version of->iphone, just a friend of the altar sent you need a post
I can also tell you how I do, in fact, is very simple, mainly with the Apple Development Account Generation certificate there to engage in.
Step 1
-------
First you have to use PHP on the server to open an interface, to provide to the iphone registration Device_token, which is loaded with your app's hand to make an HTTP request to this interface, the Device_token of each machine and some parameters submitted, and then you use PHP to receive, Save to Database
Step 2
-----------
Read the data in PHP, read the registered Device_token from the database, stitch it up into a string of prescribed formats, take the generated Apple certificate, and make a socket request to the Apple-provided push service API.
Key Code 1:
Stream_context_set_option ($ctx, ' SSL ', ' Local_cert ', $pemFile);//$pemFile for the certificate file, this is your own online search for build steps, you have to have an Apple Development Account
$ctx = Stream_context_create ();
Stream_context_set_option ($ctx, ' SSL ', ' passphrase ', $passphrase);
Open a connection to the APNS server, push service API, below is the sandbox environment
$fp = stream_socket_client (' ssl://gateway.sandbox.push.apple.com:2195 ', $err, $errstr, Stream_client_connect
------Solution--------------------
Stream_client_persistent, $ctx);
Key Code 2:
Create the payload body
$body [' aps '] = Array (
' Alert ' = = Array (
' Body ' = $message,
' Action-loc-key ' = ' Bango App ',
),
' Badge ' = $badge,
' Sound ' = ' OVEN.CAF ',
);
$deviceTokens = Array ();
$payload = Fmfactory::getjson ()->encode ($body);