iPhone Push Notification - Error response problem
Asked Answered
F

1

1

I've got a problem when checking for a response error after sending a Push Notification. This is my setup:

From my PHP server, I'm sending Push Notifications. These notifications are send in the enhanced format, so I can get an error response from the Apple server. For example: Error #7 "Invalid payload size".

The way I check for errors is reading the socket response:

const ERROR_RESPONSE_SIZE = 6;
$errorResponse = @fread($this->_apnsSocket, self::ERROR_RESPONSE_SIZE);

This works fine when there is an actual error. By my problem is: when there's no error, the "fread" call doesn't return anything and keeps loading forever.

Can anyone help me with this? Thanks for your help!

Fico answered 27/10, 2010 at 15:29 Comment(0)
S
2

You need to set stream_set_blocking($this->_apnsSocket, 0); to 0 which is non-blocking mode, because on success Apple doesn't send back anything, but the fread is waiting for data in blocking mode.

Scintillation answered 5/5, 2011 at 19:36 Comment(1)
This will work except it will also cause fread to return immediately before the error has a chance to be sent. So what you can do is an additional check for errors once you finish sending all your push notifications. Send all push, then pause for half a second, then use fread one more time to check for any errors that may have occurred with the last few push notifications that were sent. I tested this with causing an error on the last push message sent, then pausing for different lengths of time (tried up to 5 minutes), then doing an fread and the error was still there waiting to be read.Foxtail

© 2022 - 2024 — McMap. All rights reserved.