问题描述
我在发送推送通知后检查响应错误时遇到问题.这是我的设置:
I've got a problem when checking for a response error after sending a Push Notification. This is my setup:
从我的 PHP 服务器发送推送通知.这些通知以增强格式发送,因此我可以从 Apple 服务器获得错误响应.例如:错误 #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($this->_apnsSocket, 0);
设置为 0 为非阻塞模式,因为成功后,Apple 不会发回任何内容,但 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.
这篇关于iPhone 推送通知 - 错误响应问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!