发送http响应后继续处理php [英] continue processing php after sending http response
问题描述
我的脚本由服务器调用。从服务器我将收到 ID_OF_MESSAGE
和 TEXT_OF_MESSAGE
。
My script is called by server. From server I'll receive ID_OF_MESSAGE
and TEXT_OF_MESSAGE
.
在我的脚本中,我将处理传入的文本并使用参数生成响应: ANSWER_TO_ID
和 RESPONSE_MESSAGE
。
In my script I'll handle incoming text and generate response with params: ANSWER_TO_ID
and RESPONSE_MESSAGE
.
问题是我发送的回复ID_OF_MESSAGE
,但是在收到http响应200之后,向我发送消息的服务器将把他的消息设置为发送给我(这意味着我可以向他发送对该ID的响应)。
The problem is that I'm sending response to incomming "ID_OF_MESSAGE"
, but server which send me message to handle will set his message as delivered to me (It means I can send him response to that ID), after receiving http response 200.
其中一个解决方案是将消息保存到数据库并制作一些将每分钟运行的cron,但我需要立即生成响应消息。
One of solution is to save message to database and make some cron which will be running each minute, but I need to generate response message immediately.
是否有一些解决方案如何发送到服务器http响应200而不是继续执行php脚本?
Is there some solution how to send to server http response 200 and than continue executing php script?
谢谢你很多
推荐答案
是的。你可以这样做:
ignore_user_abort(true);
set_time_limit(0);
ob_start();
// do initial processing here
echo $response; // send the response
header('Connection: close');
header('Content-Length: '.ob_get_length());
ob_end_flush();
ob_flush();
flush();
// now the request is sent to the browser, but the script is still running
// so, you can continue...
这篇关于发送http响应后继续处理php的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!