Friday, January 1, 2010

Apple push notification (APN) server script with PHP

Download the scripts

testAPN.php and sendAPN.php //self documented


The script encodes the data to be sent as JSON


Please refer BoxedIce for creating certificates and to know more on how does the script works.

Common issues

Warning: stream_socket_client() [function.stream-socket-client]: unable to connect to
ssl://gateway.push.apple.com:2195 (Unable to find the socket transport "ssl" - did you forget to enable it when you configured PHP?)

Soln: Check whether OpenSSL is enabled if not kindly enable.


Warning: stream_socket_client() [function.stream-socket-client]: unable to connect to
ssl://gateway.sandbox.push.apple.com

Warning: stream_socket_client() [function.stream-socket-client]: failed to create an SSL handle

Soln:
Increase your timeout (4th argument of stream_socket_client()) and make sure that you have outgoing port 2195 open in your production environment.
This can be tested by executing following from your terminal

-bash-3.2# telnet gateway.push.apple.com 2195
Trying 17.149.38.141...
Connected to gateway.push.apple.com (17.149.38.141).
Escape character is '^]'.
Connection closed by foreign host.

1 comment: