如何使用PHP实现此方案? [英] How do i implement this scenario using PHP?
问题描述
我正在编写一个使用C2DM的android应用程序.当用户向服务器发送一些消息时,服务器将回复发件人并将该消息转发给网络中的一组其他用户.
问题是,对发件人的答复被延迟,直到将邮件转发给所有其他人为止.这需要很多时间.我希望首先将回复发送回发件人,然后执行转发过程.我怎样才能做到这一点...?如果我可以使用并行处理,如何在PHP中执行...?任何帮助将不胜感激:)
我已经使用过类似的东西
print(json_encode("Inserted Successfully"));//." ".count($tags)));
while($row = mysql_fetch_row($result))
{
$id = $row[0];
sendMessageToUserID($id,"New Question !!",$ques_id,"yyyy");
}
但是,直到执行while循环之后,插入成功"才会发送给发送者.
我不知道这是否行得通,但是您可以尝试添加Content-Length:
和Connection: close
标头,当然还要添加显式刷新的输出.>
试试这个
ob_start();
//output
header("Content-Length: ".ob_get_length());
header("Connection: close");
ob_end_flush();
//do other stuff
I am writing an android application which uses C2DM. When a user sends some message to the server, the server replies back to the sender and forwards that message to a set of other users in the network.
The problem is, the reply to the sender is delayed until the message is forwarded to all others. This is taking a lot of time. I want the reply to be sent back to sender first and then perform the forwarding process. How can i achieve this...? If i can use parallel processing, how can i do it in PHP...? Any help would be very much appreciated :)
I have used something like this,
print(json_encode("Inserted Successfully"));//." ".count($tags)));
while($row = mysql_fetch_row($result))
{
$id = $row[0];
sendMessageToUserID($id,"New Question !!",$ques_id,"yyyy");
}
But, here "Inserted Successfully" is not sent to the sender, until after the while loop is executed.
I don't know if this will work but you could try adding Content-Length:
and Connection: close
headers, and of course the explicitly flushing output.
EDIT: try this
ob_start();
//output
header("Content-Length: ".ob_get_length());
header("Connection: close");
ob_end_flush();
//do other stuff
这篇关于如何使用PHP实现此方案?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!