Skip to content

Instantly share code, notes, and snippets.

@EarthmanWeb
Last active July 3, 2024 16:18
Show Gist options
  • Save EarthmanWeb/b7f991ebb93f9132f9bd88f3b4bfbba8 to your computer and use it in GitHub Desktop.
Save EarthmanWeb/b7f991ebb93f9132f9bd88f3b4bfbba8 to your computer and use it in GitHub Desktop.
Terminus WP-CLI output test - place in /wp-content/mu-plugins
<?php
/**
* Plugin Name: Terminus Output Test
* Description: A WP-CLI command that counts to 250k with a 5 second wait per increment. Terminus is not passing WP-CLI output back to the terminal - As a result, the connection is closed after 10 minutes while the CLI command continues in the remote container with no way to stop it.
* Usage: terminus wp site.env --verbose -- terminus-output-test
* Version: 1.0
* Author: Terrance Orletsky / ChatGPT
*/
if ( defined( 'WP_CLI' ) && WP_CLI ) {
/**
* Terminus Output Test Command.
*/
class Terminus_Output_Test_Command {
/**
* Counts to 250k with a 5 second wait per increment.
*
* @when after_wp_load
*/
public function __invoke() {
// create a log file
$logfile = fopen( '/files/output-test.log', 'w' );
for ( $i = 1; $i <= 250000; $i++ ) {
// Output the current count to the terminal.
WP_CLI::line( $i );
// add an entry to a log file
fwrite( $logfile, $i . PHP_EOL );
// Wait for 5 seconds.
sleep( 5 );
}
}
}
// Register the CLI command.
WP_CLI::add_command( 'terminus-output-test', 'Terminus_Output_Test_Command' );
}
// Usage: terminus wp site.env --verbose -- terminus-output-test
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment