PHP: Prevent function return from function?

How can I make sure that the function startProcess();is called, but does not stop execution for myFunction(). I suppose there is a way to call a function and not let it return its value in order to do this in this way?

Pseudo Code:

function myFunction() {

    startProcess();

    return $something;       
}

function startProcess() {
    sleep(5);
    // Do stuff that user doesn't should have to wait for.
}
+3
source share
6 answers

You cannot do this. PHP has several functions that allow you to use asynchronous I / O, but you don't need anything like concurrency.

The reason for the lack of language support is that PHP is designed to run short-lived scripts, and concurrency is controlled by the HTTP daemon.

See also:

+5

, , , , .

, PHP . -, , PHP.

+1

startProcess()? .

: , mail(), , ; , . , , cron.

function myFunction() {
    addToQueue();
    return $something;       
}

function addToQueue() {
    // add stuff to the queue of tasks
}

function runQueue() {
    // process the queue of tasks; called by cron.
}
+1
+1

Source: https://habr.com/ru/post/1748020/


All Articles