Skip to content

Instantly share code, notes, and snippets.

@westonruter
Last active June 8, 2025 22:57
Show Gist options
  • Save westonruter/b66cfc51397c75d6497b6ed0aeb68ce3 to your computer and use it in GitHub Desktop.
Save westonruter/b66cfc51397c75d6497b6ed0aeb68ce3 to your computer and use it in GitHub Desktop.
<?php
/**
* Plugin Name: Sleepy Responses
* Plugin URI: https://gist.github.com/westonruter/b66cfc51397c75d6497b6ed0aeb68ce3
* Description: Slows down a response when a <code>sleep</code> query parameter is provided, with a value being an integer for the number of seconds passed into the PHP <code>sleep()</code> function. Only applies when <code>WP_DEBUG</code> is enabled or when <code>wp_get_environment_type()</code> returns <code>local</code> or <code>development</code>.
* Requires at least: 6.8
* Requires PHP: 7.4
* Version: 0.1.0
* Author: Weston Ruter
* Author URI: https://weston.ruter.net/
* License: GPLv2 or later
* License URI: https://www.gnu.org/licenses/old-licenses/gpl-2.0.html
* Update URI: https://gist.github.com/westonruter/b66cfc51397c75d6497b6ed0aeb68ce3
* Gist Plugin URI: https://gist.github.com/westonruter/b66cfc51397c75d6497b6ed0aeb68ce3
* Primary Branch: main
*
* @package SleepyResponses
*/
if ( isset( $_GET['sleep'] ) ) {
if ( ! ( WP_DEBUG || in_array( wp_get_environment_type(), array( 'local', 'development' ) ) ) ) {
wp_die( 'Unable to sleep when not using in debug mode or not in a local/development environment.', 'I cannot sleep!', array( 'response' => 400 ) );
}
if ( ! rest_is_integer( $_GET['sleep'] ) ) {
wp_die( 'Sleep duration must be an integer.', 'Sleep disorder!', array( 'response' => 400 ) );
}
$sleep = (int) $_GET['sleep'];
if ( $sleep <= 0 ) {
wp_die( 'Sleep duration must be a positive integer above zero.', 'Time traveler?!', array( 'response' => 400 ) );
}
sleep( $sleep );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment