Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 31 additions & 2 deletions dist-persist/wbstack/src/Internal/PreApiWbStackUpdate.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,38 @@ public function execute() {
@ini_set( 'memory_limit', '-1' ); // also try to disable the memory limit? Is this even a good idea?
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

using @ to suppress errors might hide important diagnostic errors. Can we try something like this:

if ( !set_time_limit( 60*60 ) ) {
			fwrite( STDERR, "Warning: Unable to set time limit.\n" );
}
if ( ini_set( 'memory_limit', '-1' ) === false ) {
			fwrite( STDOUT, "Warning: Unable to set memory_limit to -1\n" );
} 


// 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 2>&1';

$stdout = fopen( 'php://stdout', 'w' );
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is opened, but never closed. I suggest adding fclose($stdout) at the end to close this.


fwrite( $stdout, "DOMAIN: " . $domain . "\n" );

$spec = [ [ 'pipe', 'r' ], [ 'pipe', 'w' ],[ 'pipe', 'w' ] ];
$proc = proc_open( $cmd, $spec, $pipes );
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nitpicking: Should we check if proc_open is executed successfully?

if ($proc === false) {
  fwrite($stdout, "Error: Failed to start process \n");
} else{
...
}


$stdinProc = $pipes[0];
$stdoutProc = $pipes[1];
$stderrProc = $pipes[2];

$out = [];

$pid = ( proc_get_status( $proc ) )[ 'pid' ];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here, if $proc returns false then this will fail

fwrite( $stdout, "PID: " . $pid . "\n" );

while( $line = fgets( $stdoutProc ) ) {
$line = rtrim( $line );
fwrite( $stdout, $line . PHP_EOL );
array_push( $out, $line );
}

fclose( $stdinProc );
fclose( $stdoutProc );
fclose( $stderrProc );

$return = ( proc_get_status( $proc ) )[ 'exitcode' ];
proc_close( $proc );

// Return appropriate result
$res = [
Expand Down
33 changes: 31 additions & 2 deletions dist/wbstack/src/Internal/PreApiWbStackUpdate.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,38 @@ 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 2>&1';

$stdout = fopen( 'php://stdout', '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 . PHP_EOL );
array_push( $out, $line );
}

fclose( $stdinProc );
fclose( $stdoutProc );
fclose( $stderrProc );

$return = ( proc_get_status( $proc ) )[ 'exitcode' ];
proc_close( $proc );

// Return appropriate result
$res = [
Expand Down
Loading