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
This commit is contained in:
Andrew Ozz 2019-04-04 21:54:53 +00:00
parent adbaba7d56
commit 4601e178e5
3 changed files with 21 additions and 13 deletions

View File

@ -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
// Error reading.
$dir_size = $inaccessible;
// Stop total size calculation.
$size_total = null;
} elseif ( $dir_size === null ) {
// Timeout
// Timeout.
$dir_size = $timeout;
// Stop total size calculation.
$size_total = null;
} else {
$is_subdir = ( strpos( $size_directories[ $size ]['path'], ABSPATH ) === 0 );

View File

@ -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;

View File

@ -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.