Skip to content

Instantly share code, notes, and snippets.

@Shelob9
Created April 12, 2021 16:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Shelob9/539eee9eb4e8e292bac496de179e0796 to your computer and use it in GitHub Desktop.
Save Shelob9/539eee9eb4e8e292bac496de179e0796 to your computer and use it in GitHub Desktop.
<?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();
}
@Shelob9
Copy link
Author

Shelob9 commented Apr 12, 2021

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment