From 4601e178e5a690852c751ad9ba0a4ff071a73475 Mon Sep 17 00:00:00 2001 From: Andrew Ozz Date: Thu, 4 Apr 2019 21:54:53 +0000 Subject: [PATCH] Site health: fix usage of max_execution_time. When PHP is run from the cli the default is 0. Fixes #46645. Built from https://develop.svn.wordpress.org/trunk@45111 git-svn-id: http://core.svn.wordpress.org/trunk@44920 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-admin/includes/class-wp-debug-data.php | 20 +++++++++++++------- wp-includes/functions.php | 12 +++++++----- wp-includes/version.php | 2 +- 3 files changed, 21 insertions(+), 13 deletions(-) diff --git a/wp-admin/includes/class-wp-debug-data.php b/wp-admin/includes/class-wp-debug-data.php index b20776743e..5f96ffa41c 100644 --- a/wp-admin/includes/class-wp-debug-data.php +++ b/wp-admin/includes/class-wp-debug-data.php @@ -317,18 +317,22 @@ class WP_Debug_Data { * from causing a timeout. The default value is 30 seconds, and some * hosts do not allow you to read configuration values. */ - $max_execution_time = 30; - if ( function_exists( 'ini_get' ) ) { $max_execution_time = ini_get( 'max_execution_time' ); } + // The max_execution_time defaults to 0 when PHP runs from cli. + // We still want to limit it below. + if ( empty( $max_execution_time ) ) { + $max_execution_time = 30; + } + // Here 20 seconds is a "sensible default" for how long to make the user wait for the directory size calculation. // When testing 20 seconds seem enough in nearly all cases. The remaining edge cases are likely testing or development sites // that have very large number of files, for example `node_modules` in plugins or themes, etc. if ( $max_execution_time > 20 ) { $max_execution_time = 20; - } elseif ( $max_execution_time > 2 ) { + } elseif ( $max_execution_time > 10 ) { // If the max_execution_time is set to lower than 20 seconds, reduce it a bit to prevent // edge-case timeouts that may happen after the size loop has finished running. $max_execution_time -= 1; @@ -367,12 +371,14 @@ class WP_Debug_Data { } if ( $dir_size === false ) { - // Error reading - $dir_size = $inaccessible; + // Error reading. + $dir_size = $inaccessible; + // Stop total size calculation. $size_total = null; } elseif ( $dir_size === null ) { - // Timeout - $dir_size = $timeout; + // Timeout. + $dir_size = $timeout; + // Stop total size calculation. $size_total = null; } else { $is_subdir = ( strpos( $size_directories[ $size ]['path'], ABSPATH ) === 0 ); diff --git a/wp-includes/functions.php b/wp-includes/functions.php index 90a3bafbb6..f8d2a66216 100644 --- a/wp-includes/functions.php +++ b/wp-includes/functions.php @@ -7014,6 +7014,7 @@ function wp_direct_php_update_button() { * a blog has exceeded its allowed upload space. * * @since MU (3.0.0) + * @since 5.2.0 $max_execution_time parameter added. * * @param string $directory Full path of a directory. * @param int $max_execution_time Maximum time to run before giving up. In seconds. @@ -7051,6 +7052,7 @@ function get_dirsize( $directory, $max_execution_time = null ) { * * @since MU (3.0.0) * @since 4.3.0 $exclude parameter added. + * @since 5.2.0 $max_execution_time parameter added. * * @param string $directory Full path of a directory. * @param string $exclude Optional. Full path of a subdirectory to exclude from the total. @@ -7067,13 +7069,13 @@ function recurse_dirsize( $directory, $exclude = null, $max_execution_time = nul return false; } - if ( ! $max_execution_time ) { - // Keep the previous behavior but attempt to prevent fatal errors from timeout. + if ( $max_execution_time === null ) { + // Keep the previous behavior but attempt to prevent fatal errors from timeout if possible. if ( function_exists( 'ini_get' ) ) { $max_execution_time = ini_get( 'max_execution_time' ); } else { - // Use PHP default. - $max_execution_time = 30; + // Disable... + $max_execution_time = 0; } // Leave 1 second "buffer" for other operations if $max_execution_time has reasonable value. @@ -7095,7 +7097,7 @@ function recurse_dirsize( $directory, $exclude = null, $max_execution_time = nul } } - if ( microtime( true ) - WP_START_TIMESTAMP > $max_execution_time ) { + if ( $max_execution_time > 0 && microtime( true ) - WP_START_TIMESTAMP > $max_execution_time ) { // Time exceeded. Give up instead of risking a fatal timeout. $size = null; break; diff --git a/wp-includes/version.php b/wp-includes/version.php index 41f15c177c..69dbde9a0d 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -13,7 +13,7 @@ * * @global string $wp_version */ -$wp_version = '5.2-beta1-45110'; +$wp_version = '5.2-beta1-45111'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.