We're using APNS for our app and after suddenly getting a lot of lag on connecting to the APNS servers I found out that we're supposed to leave the connection open. I have little understanding about how stream_socket_client works and can't seem to find the answers to these questions:
- We are sending notifications to 2 different apps with 2 different certificates, is the same connection reused for both is there one open for each?
- What is the lifespan of the connection? Does it automatically close or do we need to write in something that will close them from time to time?
- How do I review the number of open connections and their information to ensure that we don't end up with duplicates or too many open connections?
- Are their any advantages to using STREAM_CLIENT_ASYNC_CONNECT instead of STREAM_CLIENT_PERSISTENT? Is async also persistent?
Here's the snippet of our connection code for your review, it is called every time a notification needs to be sent (we cannot batch notifications because our game is a turn-based word game - Wordspionage - with some tight time limits).
stream_context_set_option($ctx, 'ssl', 'local_cert', $cert); stream_context_set_option($ctx, 'ssl', 'passphrase', $passphrase);
// Open a connection to the APNS server
$url = 'ssl://gateway.push.apple.com:2195';
$fp = stream_socket_client(
$url , $err,
$errstr, 4, STREAM_CLIENT_CONNECT|STREAM_CLIENT_PERSISTENT, $ctx);
Thanks for the help!