我正在使用ApnsPHP lib为我的项目向我的用户发送推送通知:
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.
消息之间的时间太长了。有什么问题?