0
我是一個php noob,需要一些幫助。我已經構建了一個推送服務來發送推送消息給iphone。它在評論中說,將幾個消息合併到一個數據包中會更有效率。此外,現在我打電話來刪除每封郵件。我如何將幾個消息合併到一個包中?使此算法更有效
感謝
function start()
{
writeToLog('Connecting to ' . $this->server);
if (!$this->connectToAPNS())
exit;
while (true)
{
// Do at most 20 messages at a time. Note: we send each message in
// a separate packet to APNS. It would be more efficient if we
// combined several messages into one packet, but this script isn't
// smart enough to do that. ;-)
$stmt = $this->pdo->prepare('SELECT * FROM push_queue WHERE time_sent IS NULL LIMIT 20');
$stmt->execute();
$messages = $stmt->fetchAll(PDO::FETCH_OBJ);
foreach ($messages as $message)
{
if ($this->sendNotification($message->message_id, $message->device_token, $message->payload))
{
//$stmt = $this->pdo->prepare('UPDATE push_queue SET time_sent = NOW() WHERE message_id = ?');
//$stmt->execute(array($message->message_id));
$stmt = $this->pdo->prepare('DELETE FROM push_queue WHERE message_id = ?');
$stmt->execute(array($message->message_id));
}
else // failed to deliver
{
$this->reconnectToAPNS();
}
}
unset($messages);
sleep(5);
}
}
你的問題刪除這樣的郵件有無關優化SQL它是關於SQL的結果所做的任何事情......您需要解釋該部分有更多的細節來獲得可用的答案! – Yahia 2012-03-17 08:31:52