hoaproject/Console

Process: Async API

shulard opened this issue · 0 comments

Hello !

As discussed in the #72, I create an issue for this new feature. The goal here is to use Process class to run multiple scripts from the same script.

Example code here :

$procs = [];
$count = 10;
$script = "date";
while(--$count > 0)
{
    $proc = new Processus(
        $script,
        null,
        [1 => ['file', 'php://stdout', 'a']]
    );
    $proc->open();
    $procs[] = $proc;
}

while(true) {
    foreach($procs as $key => $proc) {
        $status = $proc->getStatus();
        if(false === $status['running']) {
            finishProcess($proc, $status);
            unset($procs[$key]);
        }
    }

    if(0 === count($procs)) {
        break;
    }
}

For the moment the same PID is shared by all the Process instances. As @Hywan said in the mentioned issue, there is a solution by using &.

Thanks for your help !


Want to back this issue? Post a bounty on it! We accept bounties via Bountysource.