I have a for each loop is run from an array of around 60,000 strings which is read from a file
For each of these strings I want to run a small python file with the string as an argument.
To speed things up my plan was to run each execution as a separate thread.
I tried the below but this meant that each child carried on the full foreach loop.
foreach($namesas $name)
{
pcntl_fork();
echo ++$count."\n";
exec("python script.py -argument:".$name);
}
How can I make each name run as a seperate thread? but then not continue with the main foreach loop?
pcntl_fork()creates a copy of the script which is at the same point of execution as the parent, as you’ve noticed.You can check to see if this script is the parent or the child by checking the return of
pcntl_fork():