From a4c77155fe0e52fda306b8882b9ae62d563da827 Mon Sep 17 00:00:00 2001 From: Andrew Kostka Date: Tue, 18 Apr 2023 08:33:57 +0000 Subject: [PATCH 1/6] 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/6] 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 5e07b4558c9737217332b2520e13ba9f266c6407 Mon Sep 17 00:00:00 2001 From: Deniz Erdogan Date: Thu, 20 Apr 2023 13:54:57 +0200 Subject: [PATCH 3/6] Redirect stdErr to stdOut --- dist-persist/wbstack/src/Internal/PreApiWbStackUpdate.php | 3 +-- dist/wbstack/src/Internal/PreApiWbStackUpdate.php | 3 +-- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/dist-persist/wbstack/src/Internal/PreApiWbStackUpdate.php b/dist-persist/wbstack/src/Internal/PreApiWbStackUpdate.php index 308aee3b2..59406cc39 100644 --- a/dist-persist/wbstack/src/Internal/PreApiWbStackUpdate.php +++ b/dist-persist/wbstack/src/Internal/PreApiWbStackUpdate.php @@ -21,7 +21,6 @@ public function execute() { $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" ); @@ -45,7 +44,7 @@ public function execute() { while( $line = fgets( $stderrProc ) ) { $line = rtrim( $line ); - fwrite( $stderr, $line ); + fwrite( $stdout, $line ); // effectively redirecting stdErr to stdOut array_push( $out, $line ); } diff --git a/dist/wbstack/src/Internal/PreApiWbStackUpdate.php b/dist/wbstack/src/Internal/PreApiWbStackUpdate.php index 308aee3b2..59406cc39 100644 --- a/dist/wbstack/src/Internal/PreApiWbStackUpdate.php +++ b/dist/wbstack/src/Internal/PreApiWbStackUpdate.php @@ -21,7 +21,6 @@ public function execute() { $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" ); @@ -45,7 +44,7 @@ public function execute() { while( $line = fgets( $stderrProc ) ) { $line = rtrim( $line ); - fwrite( $stderr, $line ); + fwrite( $stdout, $line ); // effectively redirecting stdErr to stdOut array_push( $out, $line ); } From 8c6389945162132d43260292a32f239ec5747521 Mon Sep 17 00:00:00 2001 From: Deniz Erdogan Date: Thu, 20 Apr 2023 14:58:39 +0200 Subject: [PATCH 4/6] Add newlines to stdout line output --- dist-persist/wbstack/src/Internal/PreApiWbStackUpdate.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/dist-persist/wbstack/src/Internal/PreApiWbStackUpdate.php b/dist-persist/wbstack/src/Internal/PreApiWbStackUpdate.php index 59406cc39..9b096b7bf 100644 --- a/dist-persist/wbstack/src/Internal/PreApiWbStackUpdate.php +++ b/dist-persist/wbstack/src/Internal/PreApiWbStackUpdate.php @@ -38,13 +38,13 @@ public function execute() { while( $line = fgets( $stdoutProc ) ) { $line = rtrim( $line ); - fwrite( $stdout, $line ); + fwrite( $stdout, $line . PHP_EOL ); array_push( $out, $line ); } while( $line = fgets( $stderrProc ) ) { $line = rtrim( $line ); - fwrite( $stdout, $line ); // effectively redirecting stdErr to stdOut + fwrite( $stdout, $line . PHP_EOL ); // effectively redirecting stdErr to stdOut array_push( $out, $line ); } From e5c2bdb68b6c964c34d7ba1ff4477af6062fe0f9 Mon Sep 17 00:00:00 2001 From: Deniz Erdogan Date: Thu, 20 Apr 2023 16:31:42 +0200 Subject: [PATCH 5/6] sync dist-persist --- dist/wbstack/src/Internal/PreApiWbStackUpdate.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/dist/wbstack/src/Internal/PreApiWbStackUpdate.php b/dist/wbstack/src/Internal/PreApiWbStackUpdate.php index 59406cc39..9b096b7bf 100644 --- a/dist/wbstack/src/Internal/PreApiWbStackUpdate.php +++ b/dist/wbstack/src/Internal/PreApiWbStackUpdate.php @@ -38,13 +38,13 @@ public function execute() { while( $line = fgets( $stdoutProc ) ) { $line = rtrim( $line ); - fwrite( $stdout, $line ); + fwrite( $stdout, $line . PHP_EOL ); array_push( $out, $line ); } while( $line = fgets( $stderrProc ) ) { $line = rtrim( $line ); - fwrite( $stdout, $line ); // effectively redirecting stdErr to stdOut + fwrite( $stdout, $line . PHP_EOL ); // effectively redirecting stdErr to stdOut array_push( $out, $line ); } From 8df826d622f0eaab7f8afc63799b8f6e349f6382 Mon Sep 17 00:00:00 2001 From: Andrew Kostka Date: Mon, 24 Apr 2023 11:27:08 +0000 Subject: [PATCH 6/6] Redirect stderr to stdout in original proc_open() command --- dist-persist/wbstack/src/Internal/PreApiWbStackUpdate.php | 8 +------- dist/wbstack/src/Internal/PreApiWbStackUpdate.php | 8 +------- 2 files changed, 2 insertions(+), 14 deletions(-) diff --git a/dist-persist/wbstack/src/Internal/PreApiWbStackUpdate.php b/dist-persist/wbstack/src/Internal/PreApiWbStackUpdate.php index 9b096b7bf..6120d9a2f 100644 --- a/dist-persist/wbstack/src/Internal/PreApiWbStackUpdate.php +++ b/dist-persist/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 = 'WBS_DOMAIN=' . $domain . ' php ' . $mwPath . '/maintenance/update.php --quick 2>&1'; $stdout = fopen( 'php://stdout', 'w' ); @@ -42,12 +42,6 @@ public function execute() { array_push( $out, $line ); } - while( $line = fgets( $stderrProc ) ) { - $line = rtrim( $line ); - fwrite( $stdout, $line . PHP_EOL ); // effectively redirecting stdErr to stdOut - array_push( $out, $line ); - } - fclose( $stdinProc ); fclose( $stdoutProc ); fclose( $stderrProc ); diff --git a/dist/wbstack/src/Internal/PreApiWbStackUpdate.php b/dist/wbstack/src/Internal/PreApiWbStackUpdate.php index 9b096b7bf..6120d9a2f 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 = 'WBS_DOMAIN=' . $domain . ' php ' . $mwPath . '/maintenance/update.php --quick 2>&1'; $stdout = fopen( 'php://stdout', 'w' ); @@ -42,12 +42,6 @@ public function execute() { array_push( $out, $line ); } - while( $line = fgets( $stderrProc ) ) { - $line = rtrim( $line ); - fwrite( $stdout, $line . PHP_EOL ); // effectively redirecting stdErr to stdOut - array_push( $out, $line ); - } - fclose( $stdinProc ); fclose( $stdoutProc ); fclose( $stderrProc );