During each iteration of a foreach loop, I would like to initialize a background process by using the exec function to pass a json file to the worker.php script.
I want each process initialized by the exec function to run in parallel. I want the remaining statements after the foreach loop in the parent script to wait for the background child process, and execute only when all the background child processes have finished. How do I do it?
Here's my php code:
foreach($inputDataGroups as $inputsForTask){
$json_string_input = json_encode($inputsForTask);
$filename = 'ImportApp_input_data_'.($group_no + 1).".json";
file_put_contents($filename,$json_string_input);
exec('php worker.php "' . $filename . '"'.' ImportApp');
$group_no++;
}
$dbappList = $this->getImportAppNameByLocationId($LocationID);
return $dbappList;