Making WordPress.org

Changeset 14220


Ignore:
Timestamp:
12/02/2024 02:38:18 AM (3 months ago)
Author:
dd32
Message:

Plugin Directory: Plugin Check: Run the plugin-check process through proc_open() so we can extract the STDERR output.

See #7840.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/shortcodes/class-upload-handler.php

    r14135 r14220  
    680680        // Run plugin check via CLI
    681681        $start_time = microtime(1);
    682         exec(
    683             'export WP_CLI_CONFIG_PATH=' . escapeshellarg( WP_CLI_CONFIG_PATH ) . '; ' .
    684             'timeout 45 ' . // Timeout after 45s if plugin-check is not done.
    685             WPCLI . ' --url=https://wordpress.org/plugins ' .
    686             'plugin check ' .
    687             '--error-severity=7 --warning-severity=6 --categories=plugin_repo --format=json ' .
    688             '--slug=' . escapeshellarg( $this->plugin_slug ) . ' ' .
    689             escapeshellarg( $this->plugin_root ),
    690             $output,
    691             $return_code
     682        $env_vars   = [
     683            'PATH'               => $_ENV['PATH'] ?? '/usr/local/bin:/usr/bin:/bin',
     684            'WP_CLI_CONFIG_PATH' => WP_CLI_CONFIG_PATH,
     685        ];
     686        $command    = WPCLI . ' --url=https://wordpress.org/plugins ' .
     687                      'plugin check ' .
     688                      '--error-severity=7 --warning-severity=6 --categories=plugin_repo --format=json ' .
     689                      '--slug=' . escapeshellarg( $this->plugin_slug ) . ' ' .
     690                      escapeshellarg( $this->plugin_root );
     691
     692        $plugin_check_process = proc_open(
     693            $command,
     694            [
     695                1 => [ 'pipe', 'w' ], // STDOUT
     696                2 => [ 'pipe', 'w' ], // STDERR
     697            ],
     698            $pipes,
     699            null,
     700            $env_vars
    692701        );
    693         $total_time = round( microtime(1) - $start_time, 1 );
     702        do {
     703            usleep( 100000 ); // 0.1s
     704
     705            $total_time = round( microtime(1) - $start_time, 1 );
     706
     707            $proc_status = proc_get_status( $plugin_check_process );
     708            $return_code = $proc_status['exitcode'] ?? 1;
     709
     710            if ( $total_time >= 45 && $proc_status['running'] ) {
     711                // Terminate it.
     712                proc_terminate( $plugin_check_process );
     713            }
     714        } while ( $proc_status['running'] && $total_time <= 60 ); // 60s max, just in case.
     715
     716        $output = explode( "\n", stream_get_contents( $pipes[1] ) );
     717        $stderr = rtrim( stream_get_contents( $pipes[2] ) );
     718
     719        // Close the process.
     720        fclose( $pipes[1] );
     721        fclose( $pipes[2] );
     722        fclose( $plugin_check_process );
    694723
    695724        /**
     
    815844            // Log plugin-check timing out.
    816845            $zip_name   = reset( $_FILES )['name'];
    817             $text       = ":rotating_light: Error: {$return_code} for {$zip_name}: {$this->plugin['Name']} ({$this->plugin_slug}) took {$total_time}s\n";
     846            $output     = implode( "\n", $output );
     847            $text       = ":rotating_light: Error: {$return_code} for {$zip_name}: {$this->plugin['Name']} ({$this->plugin_slug}) took {$total_time}s\n```{$stderr}\n===\n{$output}```";
    818848            notify_slack( PLUGIN_CHECK_LOGS_SLACK_CHANNEL, $text, wp_get_current_user(), true );
    819849        }
Note: See TracChangeset for help on using the changeset viewer.