Skip to content
This repository has been archived by the owner on Sep 20, 2021. It is now read-only.

Process: Async API #73

Open
shulard opened this issue Sep 1, 2016 · 0 comments
Open

Process: Async API #73

shulard opened this issue Sep 1, 2016 · 0 comments

Comments

@shulard
Copy link
Contributor

shulard commented Sep 1, 2016

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.

@Hywan Hywan changed the title Process: Allow to run multiple processes from the same script Process: Async API Sep 2, 2016
@Hywan Hywan self-assigned this Sep 2, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Development

No branches or pull requests

2 participants