iPhone推送通知 - 错误响应的问题

问题描述:

发送推送通知后的响应错误检查时,我有一个问题。这是我的设置:

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

从我的PHP服务器,我送推送通知。这些通知在增强格式发送,这样我可以从苹果服务器的错误响应。例如:错误#7无效的有效载荷大小

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);

这正常工作时,有一个实际的错误。我的问题是:当没有错误,FREAD调用不返回任何东西,会持续永远

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!

您需要设置 stream_set_blocking($这个 - > _apnsSocket,0); 0是非阻塞模式,因为苹果的成功并没有发回任何东西,但FREAD处于阻塞模式,等待数据。

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.