From a4c77155fe0e52fda306b8882b9ae62d563da827 Mon Sep 17 00:00:00 2001 From: Andrew Kostka Date: Tue, 18 Apr 2023 08:33:57 +0000 Subject: [PATCH 1/3] Send output of maintenance/update.php to stdout --- .../src/Internal/PreApiWbStackUpdate.php | 40 ++++++++++++++++++- 1 file changed, 38 insertions(+), 2 deletions(-) diff --git a/dist/wbstack/src/Internal/PreApiWbStackUpdate.php b/dist/wbstack/src/Internal/PreApiWbStackUpdate.php index 10958a793..308aee3b2 100644 --- a/dist/wbstack/src/Internal/PreApiWbStackUpdate.php +++ b/dist/wbstack/src/Internal/PreApiWbStackUpdate.php @@ -16,9 +16,45 @@ public function execute() { @ini_set( 'memory_limit', '-1' ); // also try to disable the memory limit? Is this even a good idea? // Run update.php + $domain = $GLOBALS[WBSTACK_INFO_GLOBAL]->requestDomain; $mwPath = realpath( __DIR__ . '/../../../' ); - $cmd = 'WBS_DOMAIN=' . $GLOBALS[WBSTACK_INFO_GLOBAL]->requestDomain . ' php ' . $mwPath . '/maintenance/update.php --quick'; - exec($cmd, $out, $return); + $cmd = 'WBS_DOMAIN=' . $domain . ' php ' . $mwPath . '/maintenance/update.php --quick'; + + $stdout = fopen( 'php://stdout', 'w' ); + $stderr = fopen( 'php://stderr', 'w' ); + + fwrite( $stdout, "DOMAIN: " . $domain . "\n" ); + + $spec = [ [ 'pipe', 'r' ], [ 'pipe', 'w' ],[ 'pipe', 'w' ] ]; + $proc = proc_open( $cmd, $spec, $pipes ); + + $stdinProc = $pipes[0]; + $stdoutProc = $pipes[1]; + $stderrProc = $pipes[2]; + + $out = []; + + $pid = ( proc_get_status( $proc ) )[ 'pid' ]; + fwrite( $stdout, "PID: " . $pid . "\n" ); + + while( $line = fgets( $stdoutProc ) ) { + $line = rtrim( $line ); + fwrite( $stdout, $line ); + array_push( $out, $line ); + } + + while( $line = fgets( $stderrProc ) ) { + $line = rtrim( $line ); + fwrite( $stderr, $line ); + array_push( $out, $line ); + } + + fclose( $stdinProc ); + fclose( $stdoutProc ); + fclose( $stderrProc ); + + $return = ( proc_get_status( $proc ) )[ 'exitcode' ]; + proc_close( $proc ); // Return appropriate result $res = [ From 419c27354e2be6a8ec3f59a8e53c1ae7544b92e0 Mon Sep 17 00:00:00 2001 From: Andrew Kostka Date: Tue, 18 Apr 2023 08:42:16 +0000 Subject: [PATCH 2/3] Update PreApiWbStackUpdate.php in dist-persist --- .../src/Internal/PreApiWbStackUpdate.php | 40 ++++++++++++++++++- 1 file changed, 38 insertions(+), 2 deletions(-) diff --git a/dist-persist/wbstack/src/Internal/PreApiWbStackUpdate.php b/dist-persist/wbstack/src/Internal/PreApiWbStackUpdate.php index 10958a793..308aee3b2 100644 --- a/dist-persist/wbstack/src/Internal/PreApiWbStackUpdate.php +++ b/dist-persist/wbstack/src/Internal/PreApiWbStackUpdate.php @@ -16,9 +16,45 @@ public function execute() { @ini_set( 'memory_limit', '-1' ); // also try to disable the memory limit? Is this even a good idea? // Run update.php + $domain = $GLOBALS[WBSTACK_INFO_GLOBAL]->requestDomain; $mwPath = realpath( __DIR__ . '/../../../' ); - $cmd = 'WBS_DOMAIN=' . $GLOBALS[WBSTACK_INFO_GLOBAL]->requestDomain . ' php ' . $mwPath . '/maintenance/update.php --quick'; - exec($cmd, $out, $return); + $cmd = 'WBS_DOMAIN=' . $domain . ' php ' . $mwPath . '/maintenance/update.php --quick'; + + $stdout = fopen( 'php://stdout', 'w' ); + $stderr = fopen( 'php://stderr', 'w' ); + + fwrite( $stdout, "DOMAIN: " . $domain . "\n" ); + + $spec = [ [ 'pipe', 'r' ], [ 'pipe', 'w' ],[ 'pipe', 'w' ] ]; + $proc = proc_open( $cmd, $spec, $pipes ); + + $stdinProc = $pipes[0]; + $stdoutProc = $pipes[1]; + $stderrProc = $pipes[2]; + + $out = []; + + $pid = ( proc_get_status( $proc ) )[ 'pid' ]; + fwrite( $stdout, "PID: " . $pid . "\n" ); + + while( $line = fgets( $stdoutProc ) ) { + $line = rtrim( $line ); + fwrite( $stdout, $line ); + array_push( $out, $line ); + } + + while( $line = fgets( $stderrProc ) ) { + $line = rtrim( $line ); + fwrite( $stderr, $line ); + array_push( $out, $line ); + } + + fclose( $stdinProc ); + fclose( $stdoutProc ); + fclose( $stderrProc ); + + $return = ( proc_get_status( $proc ) )[ 'exitcode' ]; + proc_close( $proc ); // Return appropriate result $res = [ From cdc36dc3621d3252c4cbbf254fecc6c286c07b3f Mon Sep 17 00:00:00 2001 From: Thomas Arrow Date: Tue, 18 Apr 2023 16:23:37 +0100 Subject: [PATCH 3/3] DNM: test existance of order of stderr --- dist/maintenance/testOutputOrder.sh | 6 ++++++ dist/wbstack/src/Internal/PreApiWbStackUpdate.php | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) create mode 100755 dist/maintenance/testOutputOrder.sh diff --git a/dist/maintenance/testOutputOrder.sh b/dist/maintenance/testOutputOrder.sh new file mode 100755 index 000000000..e53139fa8 --- /dev/null +++ b/dist/maintenance/testOutputOrder.sh @@ -0,0 +1,6 @@ +#!/bin/bash +echo "Standard out 1" +echo "Standard error 1" 1>&2 +sleep 20s +echo "Standard out 2" +echo "Standard error 2" 1>&2 diff --git a/dist/wbstack/src/Internal/PreApiWbStackUpdate.php b/dist/wbstack/src/Internal/PreApiWbStackUpdate.php index 308aee3b2..815fcc2be 100644 --- a/dist/wbstack/src/Internal/PreApiWbStackUpdate.php +++ b/dist/wbstack/src/Internal/PreApiWbStackUpdate.php @@ -18,7 +18,7 @@ public function execute() { // Run update.php $domain = $GLOBALS[WBSTACK_INFO_GLOBAL]->requestDomain; $mwPath = realpath( __DIR__ . '/../../../' ); - $cmd = 'WBS_DOMAIN=' . $domain . ' php ' . $mwPath . '/maintenance/update.php --quick'; + $cmd = 'bash ' . $mwPath . '/maintenance/testOutputOrder.sh'; $stdout = fopen( 'php://stdout', 'w' ); $stderr = fopen( 'php://stderr', 'w' );