Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
420 views
in Technique[技术] by (71.8m points)

parallel processing - How do i implement this scenario using PHP?

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...