I have see lots of code sample of exec and system which can be use to run some php code in background.
<?php 
include_once('mail.php');
$response = array();    
            
// This Code Should Execute Without waiting for other code;
$response['status'] = true;
$response['msg'] = "Thank you  Welcome in SAAS Application. We will connect with you soon. :)";// Send response to webpage first then execute below code.   ;
echo json_encode($response);            
//THIS CODE SHOULD EXECUTE IN BACKGROUND WHICH COMES FROM INCLUDE MAIL.PHP
sometimeTakingFunction($conn,$msg)  
    
?>
The exec code i found which can run my function in background but i am confused where to put or how to use my function in exec
exec(sprintf("%s > %s 2>&1 & echo $! >> %s", $cmd, $outputfile, $pidfile));
System can also use to run in background but no clue how to use it.
system("php script2.php &");
sometimeTakingFunction i have needs to work in background in php. Can anyone guide me how to use my sometimeTakingFunction($param1,$param2); in background without blocking the code i have above it.
I see system and exec which can be helpful in running background php code. As a newbie in php i don't understand how to add my sometimeTakingFunction($param1,$param2,$param3) functions in these.
I found a link which shows different ways to run php in background but not as required. Anyone know how can i run my function in background. I am using ubuntu for my php.
 
    