4

It's been now a week that I am searching answers for the problem I have, but I can't find anything, so I am going to ask the question here!

I made an iPhone application that can send notifications to the users. So, I have a notification server, coded in PHP, and which uses apns-php (http://code.google.com/p/apns-php/)

My server can send notifications at any time, so I have a worker that runs indefinitely, and each time it receives a notification to send (the notifications to send are in a queue), it sends the notification. To be the fastest possible, the worker has 10 threads that can send notifications.

When I start the worker, I receive the notifications I am suppose to receive.

The problem is that after a while (I don't know if it is after a specific amount of time or a specific amount of notifications sent ... or something else!), I do not receive any new notification. And when I look at the logs of apns-php, there is nothing : all the messages seem to be sent to the APNS service, with no error (apns-php uses the enhanced format). Once I restart the worker, I receive notifications again (but only for a while).

I've searched for this problem in stackoverflow and on Google, and so far, the only responses I saw were:

  • There is a problem in the certificate/profile used. I know that can't be the problem, because I receive the notifications when I start the worker
  • There are some development device tokens in our database, which makes APNS close the connection. Indeed, it is possible that some development device tokens are present in our database, but when I look to the apns-php code, if the connection is closed, a new one is opened. So I don't understand how can this impact all the notifications sent after a bad device token.

This problem is really driving me crazy, because the notifications are really important for our service. So if anyone has an idea of what could be the problem here, it would really be a life saver!

PS: I haven't posted any code because there isn't anything specific that I'm doing. I'm just using the send() function of apns-php for each notification to send.

Talal MAZROUI
  • 645
  • 1
  • 6
  • 12

1 Answers1

0

I finally found the source of my problem : If there is no activity on a opened connection to APNS during 2 hours, the connection times out and APNS closes the connection.

I still don't understand why apns-php does not detect that the connection is closed. But I solved it by automatically reconnecting to APNS every time I send a notification after a period of inactivity of 30 minutes (I could have chosen 2 hours, but I just want to be sure to have no problem).

Talal MAZROUI
  • 645
  • 1
  • 6
  • 12
  • would you post your modification? I have similar problem but I am using nodejs :( – Zennichimaro Jun 01 '13 at 22:32
  • I just store a variable with the last connect time, and every time I send a notification, I check the last connect time. If it is greater than 30 minutes, I reconnect. – Talal MAZROUI Jun 03 '13 at 12:56