Site Health: Detect an active PHP session as a possible reason for HTTP requests timing out.

PHP sessions created by a `session_start()` function call may interfere with REST API and loopback requests.

An active session should be closed by `session_write_close()` before making any HTTP requests.

Props matthieumota, netweblogic, Clorith, afragen, vjik, SergeyBiryukov.
Fixes #47320.
Built from https://develop.svn.wordpress.org/trunk@47585


git-svn-id: http://core.svn.wordpress.org/trunk@47360 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Sergey Biryukov 2020-04-16 08:20:09 +00:00
parent 4e13efaf96
commit 92538d89ee
2 changed files with 51 additions and 1 deletions

View File

@ -1083,6 +1083,52 @@ class WP_Site_Health {
return $result;
}
/**
* Test if there's an active PHP session that can affect loopback requests.
*
* @since 5.5.0
*
* @return array The test results.
*/
public function get_test_php_sessions() {
$result = array(
'label' => __( 'No PHP sessions detected' ),
'status' => 'good',
'badge' => array(
'label' => __( 'Performance' ),
'color' => 'blue',
),
'description' => sprintf(
'<p>%s</p>',
sprintf(
/* translators: 1: session_start(), 2: session_write_close() */
__( 'PHP sessions created by a %1$s function call may interfere with REST API and loopback requests. An active session should be closed by %2$s before making any HTTP requests.' ),
'<code>session_start()</code>',
'<code>session_write_close()</code>'
)
),
'test' => 'php_sessions',
);
if ( PHP_SESSION_ACTIVE === session_status() ) {
$result['status'] = 'critical';
$result['label'] = __( 'An active PHP session was detected' );
$result['description'] = sprintf(
'<p>%s</p>',
sprintf(
/* translators: 1: session_start(), 2: session_write_close() */
__( 'A PHP session was created by a %1$s function call. This interferes with REST API and loopback requests. The session should be closed by %2$s before making any HTTP requests.' ),
'<code>session_start()</code>',
'<code>session_write_close()</code>'
)
);
}
return $result;
}
/**
* Test if the SQL server is up to date.
*
@ -1939,6 +1985,10 @@ class WP_Site_Health {
'label' => __( 'PHP Default Timezone' ),
'test' => 'php_default_timezone',
),
'php_sessions' => array(
'label' => __( 'PHP Sessions' ),
'test' => 'php_sessions',
),
'sql_server' => array(
'label' => __( 'Database Server version' ),
'test' => 'sql_server',

View File

@ -13,7 +13,7 @@
*
* @global string $wp_version
*/
$wp_version = '5.5-alpha-47584';
$wp_version = '5.5-alpha-47585';
/**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.