WordPress.org

Make WordPress Core

Changeset 45111


Ignore:
Timestamp:
04/04/2019 09:53:45 PM (6 months ago)
Author:
azaozz
Message:

Site health: fix usage of max_execution_time. When PHP is run from the cli the default is 0.

Fixes #46645.

Location:
trunk/src
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/includes/class-wp-debug-data.php

    r45110 r45111  
    318318         * hosts do not allow you to read configuration values.
    319319         */
    320         $max_execution_time = 30;
    321 
    322320        if ( function_exists( 'ini_get' ) ) {
    323321            $max_execution_time = ini_get( 'max_execution_time' );
     322        }
     323
     324        // The max_execution_time defaults to 0 when PHP runs from cli.
     325        // We still want to limit it below.
     326        if ( empty( $max_execution_time ) ) {
     327            $max_execution_time = 30;
    324328        }
    325329
     
    329333        if ( $max_execution_time > 20 ) {
    330334            $max_execution_time = 20;
    331         } elseif ( $max_execution_time > 2 ) {
     335        } elseif ( $max_execution_time > 10 ) {
    332336            // If the max_execution_time is set to lower than 20 seconds, reduce it a bit to prevent
    333337            // edge-case timeouts that may happen after the size loop has finished running.
     
    368372
    369373            if ( $dir_size === false ) {
    370                 // Error reading
    371                 $dir_size   = $inaccessible;
     374                // Error reading.
     375                $dir_size = $inaccessible;
     376                // Stop total size calculation.
    372377                $size_total = null;
    373378            } elseif ( $dir_size === null ) {
    374                 // Timeout
    375                 $dir_size   = $timeout;
     379                // Timeout.
     380                $dir_size = $timeout;
     381                // Stop total size calculation.
    376382                $size_total = null;
    377383            } else {
  • trunk/src/wp-includes/functions.php

    r45104 r45111  
    70157015 *
    70167016 * @since MU (3.0.0)
     7017 * @since 5.2.0 $max_execution_time parameter added.
    70177018 *
    70187019 * @param string $directory Full path of a directory.
     
    70527053 * @since MU (3.0.0)
    70537054 * @since 4.3.0 $exclude parameter added.
     7055 * @since 5.2.0 $max_execution_time parameter added.
    70547056 *
    70557057 * @param string $directory Full path of a directory.
     
    70687070    }
    70697071
    7070     if ( ! $max_execution_time ) {
    7071         // Keep the previous behavior but attempt to prevent fatal errors from timeout.
     7072    if ( $max_execution_time === null ) {
     7073        // Keep the previous behavior but attempt to prevent fatal errors from timeout if possible.
    70727074        if ( function_exists( 'ini_get' ) ) {
    70737075            $max_execution_time = ini_get( 'max_execution_time' );
    70747076        } else {
    7075             // Use PHP default.
    7076             $max_execution_time = 30;
     7077            // Disable...
     7078            $max_execution_time = 0;
    70777079        }
    70787080
     
    70967098                }
    70977099
    7098                 if ( microtime( true ) - WP_START_TIMESTAMP > $max_execution_time ) {
     7100                if ( $max_execution_time > 0 && microtime( true ) - WP_START_TIMESTAMP > $max_execution_time ) {
    70997101                    // Time exceeded. Give up instead of risking a fatal timeout.
    71007102                    $size = null;
Note: See TracChangeset for help on using the changeset viewer.