【发布时间】:2015-07-11 15:10:33
【问题描述】:
我正在为我的项目使用 ApnsPHP 库向我的用户发送推送通知:
private static function fnSendToIos($tokens, $text, $config)
{
set_time_limit(200);
// Adjust to your timezone
date_default_timezone_set('Europe/Moscow');
// Using Autoload all classes are loaded on-demand
require_once 'ApnsPHP/Autoload.php';
// Instantiate a new ApnsPHP_Push object
$push = new ApnsPHP_Push(
ApnsPHP_Abstract::ENVIRONMENT_SANDBOX,
$config['sert']
);
// Set the Root Certificate Autority to verify the Apple remote peer
$push->setRootCertificationAuthority($config['RootCertificat']);
// Connect to the Apple Push Notification Service
$push->connect();
// Instantiate a new Message with a single recipient
$message = new ApnsPHP_Message();
//Put all tokens as recipients in one message
foreach ($tokens as $token) {
$message->addRecipient($token);
}
// Set a custom identifier. To get back this identifier use the getCustomIdentifier() method
// over a ApnsPHP_Message object retrieved with the getErrors() message.
$message->setCustomIdentifier("Message-Badge-1");
// Set badge icon to "1"
$message->setBadge(1);
// Play the default sound
$message->setSound();
// Set a simple welcome text
$message->setText($text);
// Add the message to the message queue
$push->add($message);
// Send all messages in the message queue
$push->send();
// Disconnect from the Apple Push Notification Service
$push->disconnect();
// Examine the error message container
$aErrorQueue = $push->getErrors();
if (!empty($aErrorQueue)) {
log2file('iosPushNotifications', 'Send push notifications err:' . print_r($aErrorQueue));
}
}
但它的工作速度很慢。第一条消息运行得很快,但每条下一条都需要 1 分钟或更长时间。 日志文件:
2015-05-01 17:58:30 UTC 192.168.2.1 a3d05958a5f7acdede098a2369ea7782
INFO: Trying ssl://gateway.sandbox.push.apple.com:2195...
2015-05-01 17:58:31 UTC 192.168.2.1 749386767ecdb42b51961dc90cfce4c4
INFO: Connected to ssl://gateway.sandbox.push.apple.com:2195.
2015-05-01 17:58:31 UTC 192.168.2.1 aacaa098ebce25abd2848d37962f0ae8
INFO: Sending messages queue, run #1: 2 message(s) left in queue.
2015-05-01 17:58:31 UTC 192.168.2.1 bde685d96b4309af2d9b8d592576f48d
STATUS: Sending message ID 1 [custom identifier: Message-Badge-1] (1/3): 150 bytes.
2015-05-01 17:59:31 UTC 192.168.2.1 1bdbc022e1037b8be36e40bb883c364c
STATUS: Sending message ID 2 [custom identifier: Message-Badge-1] (1/3): 150 bytes.
2015-05-01 18:00:32 UTC 192.168.2.1 7a81d80022327339521d4ba54b64c4cf
INFO: Disconnected.
消息之间的时间过长。怎么了?
【问题讨论】:
-
您的服务器在地理位置上位于何处?它的网络速度是多少?如果您尝试将 curl 请求发送到另一台服务器(大概在美国),它是否同样慢?
-
互联网运行速度很快。 Android pushNotifications 也很快。
-
您知道要向其发送请求的服务器的地址吗?如果是这样,您的服务器上的 traceroute/ping 测试显示了什么?
-
不,下面的代码可以正常工作。 Tnx。
标签: php notifications apple-push-notifications push