I need to send some images through tesseract, and to save time I want to run tesseract in parallel with up to 6 instances.
I have looked at this question, but cant really figure out how to write the code
How can one use multi threading in PHP applications
All images are fetched from a database, and the results are written back to the specific row in the database together with the rest of the information related to the image
Could anyone link to an example or could anyone write a quick example on how to do the job?
When a process is completed a new one must be started so there will always be up to 6 processes running at the same time?
update
class Command {
private $descriptorspec;
private $output = '';
public function __construct(){
$this->descriptorspec = [
0 => ['pipe', 'r'], // stdin
1 => ['pipe', 'w'], // stdout
2 => ['pipe', 'w'], // stderr
];
}
public function output(): string{
return $this->output;
}
public function exec(string $syntax): string{
$process = proc_open($syntax, $this->descriptorspec, $pipes);
$this->output = stream_get_contents($pipes[1]);
fclose($pipes[1]);
$stderr = stream_get_contents($pipes[2]);
fclose($pipes[2]);
proc_close($process);
return $stderr;
}
}
$Cmd = new Command;
$Cmd->exec('tesseract ...');