misksa
misksa

Reputation: 1

How to continue performing asynchronous actions after return in php?

I'm just a beginner, please tell me if it is possible to return the result from a php function, but at the same time so that asynchronous actions continue to work in it using the amphp library?

example:


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();

Let's assume that the "run" function accepts a request, func1 implies actions that need to be performed and based on them return a response to the client, future1 are actions that we do not need to wait for to return a response to the client.

Well, this is the main question, how to achieve this behavior? Any tips, links, directions, explanations 😊 🙏

Upvotes: 0

Views: 74

Answers (0)

Related Questions