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.

git-svn-id: https://develop.svn.wordpress.org/trunk@47585 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Sergey Biryukov 2020-04-16 08:18:49 +00:00
parent 90b0f49b1a
commit cb29ca927c

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',