Created
April 12, 2021 16:58
-
-
Save Shelob9/539eee9eb4e8e292bac496de179e0796 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function batch_cli( $command, $totalPages,$loop ) { | |
$state = new \stdClass(); | |
$state->page = 1; | |
$state->totalPages = $totalPages; | |
$state->command = $command; | |
$createProcess = function($state){ | |
return new Process(sprintf( "%s --page=%n", $state->command, $state->page ); | |
}; | |
$first = $createProcess($state); | |
$first->start($loop); | |
$first->on('exit', function () use ($loop,$state) { | |
$state->page = $state->page + 1; | |
if( $state->page !== $state->pageTotal ){ | |
$next = new Process('cat second'); | |
$next->start($loop); | |
} | |
}); | |
$loop = React\EventLoop\Factory::create(); | |
batch_cli('wp something', 17, $loop ); | |
$loop->run(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://github.com/reactphp/child-process