Make WordPress Core


Ignore:
Timestamp:
02/22/2021 12:49:17 AM (4 years ago)
Author:
peterwilsoncc
Message:

Site Health: Update loopback test to POST to wp-cron.

Replace loopback health check URL with a POST request to wp-cron.php in the WordPress install directory. This more closely represents how WordPress uses loopback requests.

A POST request is used to cause wp-cron.php to exit prior to running any cron jobs. This allows the test to indicate success quicker and accounts for sites that set the DISABLE_WP_CRON constant to avoid running cron jobs on loopback requests.

Props clorith, peterwilsoncc, TimothyBlynJacobs.
Fixes #52547.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/includes/class-wp-site-health.php

    r50381 r50399  
    26482648     */
    26492649    function can_perform_loopback() {
     2650        $body    = array( 'site-health' => 'loopback-test' );
    26502651        $cookies = wp_unslash( $_COOKIE );
    26512652        $timeout = 10;
     
    26612662        }
    26622663
    2663         $url = home_url();
    2664 
    2665         $r = wp_remote_get( $url, compact( 'cookies', 'headers', 'timeout', 'sslverify' ) );
     2664        $url = site_url( 'wp-cron.php' );
     2665
     2666        /*
     2667         * A post request is used for the wp-cron.php loopback test to cause the file
     2668         * to finish early without triggering cron jobs. This has two benefits:
     2669         * - cron jobs are not triggered a second time on the site health page,
     2670         * - the loopback request finishes sooner providing a quicker result.
     2671         *
     2672         * Using a POST request causes the loopback to differ slightly to the standard
     2673         * GET request WordPress uses for wp-cron.php loopback requests but is close
     2674         * enough. See https://core.trac.wordpress.org/ticket/52547
     2675         */
     2676        $r = wp_remote_post( $url, compact( 'body', 'cookies', 'headers', 'timeout', 'sslverify' ) );
    26662677
    26672678        if ( is_wp_error( $r ) ) {
Note: See TracChangeset for help on using the changeset viewer.