提问人:misksa 提问时间:8/22/2023 更新时间:8/22/2023 访问量:45
在php中返回后如何继续执行异步操作?
How to continue performing asynchronous actions after return in php?
问:
我只是一个初学者,请告诉我是否可以从 php 函数返回结果,但同时使用 amphp 库让异步操作继续在其中工作?
例:
function run () {
$func1 = function () {
//the main action from which you need to get an answer
$result = "Result";
return $result;
};
$future1 = Amp\async(function () {
Amp\delay(3);
//not the main action
echo 'DB, or any Request';
});
$future1->await();
return $func1();
};
run();
假设 “run” 函数接受一个请求,func1 表示需要执行的操作,并基于它们向客户端返回响应,future1 是我们不需要等待向客户端返回响应的操作。
那么,这是主要问题,如何实现这种行为?任何提示、链接、方向、解释 😊 🙏
答: 暂无答案
评论