';
echo '
' . esc_html__( 'Cache Tester', 'wp-super-cache' ) . '
';
echo '
' . esc_html__( 'Test your cached website by clicking the test button below.', 'wp-super-cache' ) . '
';
echo '
' . __( 'Note: if you use Cloudflare or other transparent front-end proxy service this test may fail.
- If you have Cloudflare minification enabled this plugin may detect differences in the pages and report an error.
- Try using the development mode of Cloudflare to perform the test. You can disable development mode afterwards if the test succeeds.
', 'wp-super-cache' ) . '';
if ( array_key_exists( 'action', $_POST ) && 'test' === $_POST['action'] && $valid_nonce ) {
$url = trailingslashit( get_bloginfo( 'url' ) );
if ( isset( $_POST['httponly'] ) ) {
$url = str_replace( 'https://', 'http://', $url );
}
$test_messages = array( esc_html__( 'Fetching %s to prime cache: ', 'wp-super-cache' ), esc_html__( 'Fetching first copy of %s: ', 'wp-super-cache' ), esc_html__( 'Fetching second copy of %s: ', 'wp-super-cache' ) );
$c = 0;
$cache_test_error = false;
$page = array();
foreach ( $test_messages as $message ) {
echo '
' . sprintf( $message, $url );
$page[ $c ] = wp_remote_get( $url, array( 'timeout' => 60, 'blocking' => true ) );
if ( ! is_wp_error( $page[ $c ] ) ) {
$fp = fopen( $cache_path . $c . '.html', 'w' );
fwrite( $fp, $page[ $c ]['body'] );
fclose( $fp );
echo '' . esc_html__( 'OK', 'wp-super-cache' ) . " (" . $c . '.html)
';
sleep( 1 );
} else {
$cache_test_error = true;
echo '
' . esc_html__( 'FAILED', 'wp-super-cache' ) . '';
$errors = '';
$messages = '';
foreach ( $page[ $c ]->get_error_codes() as $code ) {
$severity = $page[ $c ]->get_error_data( $code );
foreach ( $page[ $c ]->get_error_messages( $code ) as $err ) {
$errors .= $severity . ': ' . $err . "
\n";
}
}
if ( ! empty( $errors ) ) {
echo '
' . sprintf( __( 'Errors: %s', 'wp-super-cache' ), $errors ) . '
';
}
}
++$c;
}
if ( false == $cache_test_error ) {
echo '
- ' . sprintf( esc_html__( 'Page %d: %d (%s)', 'wp-super-cache' ), 1, intval( $page[1]['response']['code'] ), esc_attr( $page[1]['response']['message'] ) ) . '
';
echo '- ' . sprintf( esc_html__( 'Page %d: %d (%s)', 'wp-super-cache' ), 2, intval( $page[2]['response']['code'] ), esc_attr( $page[2]['response']['message'] ) ) . '
';
}
if ( false == $cache_test_error && preg_match( '/(Cached page generated by WP-Super-Cache on) ([0-9]*-[0-9]*-[0-9]* [0-9]*:[0-9]*:[0-9]*)/', $page[1]['body'], $matches1 ) &&
preg_match( '/(Cached page generated by WP-Super-Cache on) ([0-9]*-[0-9]*-[0-9]* [0-9]*:[0-9]*:[0-9]*)/', $page[2]['body'], $matches2 ) && $matches1[2] == $matches2[2]
) {
echo '
' . sprintf( esc_html__( 'Page 1: %s', 'wp-super-cache' ), $matches1[2] ) . '
';
echo '
' . sprintf( esc_html__( 'Page 2: %s', 'wp-super-cache' ), $matches2[2] ) . '
';
echo '
' . esc_html__( 'The timestamps on both pages match!', 'wp-super-cache' ) . '
';
} else {
echo '
' . esc_html__( 'The pages do not match! Timestamps differ or were not found!', 'wp-super-cache' ) . '
';
echo '
' . esc_html__( 'Things you can do:', 'wp-super-cache' ) . '
';
echo '
- ' . esc_html__( 'Load your homepage in a logged out browser, check the timestamp at the end of the html source. Load the page again and compare the timestamp. Caching is working if the timestamps match.', 'wp-super-cache' ) . '
';
echo '- ' . esc_html__( 'Enable logging on the Debug page here. That should help you track down the problem.', 'wp-super-cache' ) . '
';
echo '- ' . esc_html__( 'You should check Page 1 and Page 2 above for errors. Your local server configuration may not allow your website to access itself.', 'wp-super-cache' ) . '
';
echo '
';
}
}
echo '
';
echo '
';
}
echo '