How can a client send a request to a server just to trigger an execution, where the server immediately sends a response then executes the requested code? Similar to this:
echo 'the execution is starting';
exit;
execution_function(); // <--- is it possible to this function being executed after exit
I want the response to be immediate so the client can do other things while the server executes the request.
The exit() function in PHP is an inbuilt function which is used to output a message and terminate the current script. The exit() function only terminates the execution of the script. The shutdown functions and object destructors will always be executed even if exit() function is called.
The return keyword ends a function and, optionally, uses the result of an expression as the return value of the function. If return is used outside of a function, it stops PHP code in the file from running.
PHP code is executed on the server.
You can use register_shutdown_function() to set a callback function which will be executed when PHP exits.
You can use register_shutdown_function() after exit() , die() , even you can register fatal error to your error register log using this function.Quite handy
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With