我的脚本由服务器调用。从服务器我会收到ID_OF_MESSAGE
and TEXT_OF_MESSAGE
.
在我的脚本中,我将处理传入的文本并使用参数生成响应:ANSWER_TO_ID
and RESPONSE_MESSAGE
.
问题是我正在发送对传入的响应"ID_OF_MESSAGE"
,但是向我发送消息来处理的服务器在收到 http 响应 200 后,会将其消息设置为已传递给我(这意味着我可以向他发送对该 ID 的响应)。
解决方案之一是将消息保存到数据库并创建一些每分钟运行一次的 cron,但我需要立即生成响应消息。
有没有一些解决方案如何发送到服务器http响应200然后继续执行php脚本?
万分感谢
是的。你可以这样做:
ignore_user_abort(true);//not required
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();
fastcgi_finish_request();//required for PHP-FPM (PHP > 5.3.3)
// now the request is sent to the browser, but the script is still running
// so, you can continue...
die(); //a must especially if set_time_limit=0 is used and the task ends
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)