gpt4 book ai didi

php - 发送http响应后继续处理php

转载 作者:IT老高 更新时间:2023-10-28 11:53:23 25 4
gpt4 key购买 nike

我的脚本被服务器调用。从服务器我会收到 ID_OF_MESSAGETEXT_OF_MESSAGE

在我的脚本中,我将处理传入的文本并使用参数生成响应:ANSWER_TO_IDRESPONSE_MESSAGE

问题是我正在发送对传入 "ID_OF_MESSAGE" 的响应,但是向我发送消息要处理的服务器会将他的消息设置为已发送给我(这意味着我可以向他发送响应那个ID),在收到http响应200之后。

解决方案之一是将消息保存到数据库并制作一些每分钟运行的 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

关于php - 发送http响应后继续处理php,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15273570/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com