I am using PHP to connect to APNS and generally it works fine - I'm still in the sandbox environment, I haven't used production yet. I initially used PHP code based on the Ray Wenderlich pushchat tutorial and then moved to ApnsPHP, running on Ubuntu. My server process makes its connection, polls the database to see if any messages have to be sent, sends them, sleeps a bit and then polls again.
Both attempts have displayed the same problem. After a period of inactivity (eg overnight), the first message will not be sent to the device. No error is reported and the number of bytes written to the socket is correct. However, when I send the second message, it fails with zero bytes written.
Is this expected behaviour? I haven't seen any specific reference to it anywhere, although Apple advise persisting the socket connection, unless "you know it will be idle for an extended period of time". My messages are a result of user activity, so I can not predict whether the system will be idle or not.
I assume the connection has timed-out in some way, so is there a way of double-checking the viability of the socket connection?
I can think of a couple of ways round the problem, such as re-sending the message sent prior to a failure or monitoring how long my connection is idle and re-connecting after a certain period. But if I did that, what would be a reasonable period of time?
Has anyone else seen this and is there a best practise way of handling it?