PHP "Push" function for "multiple" terminal devices

Source: Internet
Author: User
PHP Terminal push

How to implement the push information function of iOS and other devices with PHP code?

There may be many end devices that need to receive push messages and execute a script to push multiple times

Pass by to give some useful advice, thank you


Reply to discussion (solution)

Tell me more about it, send ipad or cash?

What triggers? What content is pushed?

Tell me more about it, send ipad or cash?

What triggers? What content is pushed?

I saw this on the Internet.
http://www.iteye.com/topic/1130630

is similar to the push sent by Apple to the mobile phone, content casually

Now that you have seen the relevant articles, why are you still asking here?
Here is only to give you the idea, the specific code to write their own

The principle is nothing more than to establish a connection (socket similar), from the server to the device to send bytes, the device side after receiving how to deal with it? Direct Display, popup window, notifications, flashing reminders, etc.

There are two ways of doing
1. Server as a service side, a variety of devices as a client, establish a long connection, the server based on trigger conditions sent, the practice is a bit like chat room
2. Reverse thinking, all kinds of equipment as a service side (not written wrong, is the server), log on to the servers and note their listening ip/port (login is not necessarily sent, the purpose is to submit online status), the server according to the trigger conditions in addition to run the client program to all the logged on devices to submit a connection request, The connection is sent successfully

Now that you have seen the relevant articles, why are you still asking here?
Here is only to give you the idea, the specific code to write their own

The principle is nothing more than to establish a connection (socket similar), from the server to the device to send bytes, the device side after receiving how to deal with it? Direct Display, popup window, notifications, flashing reminders, etc.

There are two ways of doing
1. Server as a service side, a variety of devices as a client, establish a long connection, the server based on trigger conditions sent, the practice is a bit like chat room
2. Reverse thinking, all kinds of equipment as a service side (not written wrong, is the server), log on to the servers and note their listening ip/port (login is not necessarily sent, the purpose is to submit online status), the server according to the trigger conditions in addition to run the client program to all the logged on devices to submit a connection request, The connection is sent successfully


Must not be realized, just ask!

But thank you for your guidance, though it doesn't work for me.

$fp = Stream_socket_client ("Ssl://gateway.sandbox.push.apple.com:2195″, $err, $ERRSTR, 60,

Stream_client_connect, $ctx);
The point is this. The app wants to register with Apple's server to receive notifications, and when it's registered, it sends a message to Apple's server and the Apple server completes the push.
Instead of PHP being pushed directly into the app.

$fp = Stream_socket_client ("Ssl://gateway.sandbox.push.apple.com:2195″, $err, $ERRSTR, 60,

Stream_client_connect, $ctx);
The point is this. The app wants to register with Apple's server to receive notifications, and when it's registered, it sends a message to Apple's server and the Apple server completes the push.
Instead of PHP being pushed directly into the app.

That's the problem.

$deviceToken = ' 5a25d318035c3be9c2ca00572b81463c73c433aea6c738540d46db6a64f70125 ';//$deviceToken =$_request[" Token "];//push method, containing content and sound $body = Array (" APS "= +" + "," badge "and" Push Test "," sound "=" default ");// Create a data Flow context object $ctx = Stream_context_create ();//Set PEM format File//$pem = DirName (__file__). '/' . ' Server_certificates_bundle_sandbox.pem '; $pem = "Server_certificates_bundle_sandbox.pem"; echo $PEM;//Set the local authentication certificate for the data Flow context stream_context_set_option ($ctx, "SSL", "Local_cert", $PEM);  $pass = "";//Set the password of the data flow context stream_context_set_option ($ctx, ' SSL ', ' passphrase ', $pass); Product Release APNs server, gateway.push.apple.com//Test APNs server, gateway.sandbox.push.apple.com//socket communication $fp = stream_socket_ Client ("ssl://gateway.push.apple.com:2195", $err, $errstr, stream_client_connect| Stream_client_persistent, $ctx); if (! $fp) {echo "Failed to connect to Apple server."; return;} Print "Connect apple server ok\n";//load information, JSON code $payload = Json_encode ($body); Constructs the sent binary information $msg = chr (0). Pack ("n", 32). Pack ("h*", Str_replace ("," ", $deviceToken)). Pack ("N ", strlen ($payload)). $payload; echo "Send message:". $payload. " \ n "; fwrite ($fp, $msg); fclose ($FP);


Now the browser opens, direct display can not connect the Apple server ...

That is, the socket communication is unsuccessful, and I don't know what happened.

The browser is accessing this: https://gateway.push.apple.com:2195/
In the program is the SSL protocol.
Devicetoken and certificate account password have you got it?

Token and account password, this is from iOS to me

Did you implement this push feature? One piece of content pushes up to multiple devices at the same time!
How did you do it, please?

  • Related Article

    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.