Skip to content

Instantly share code, notes, and snippets.

@adentify
Created August 12, 2016 13:09
Show Gist options
  • Select an option

  • Save adentify/9a53eec0c2d69a18c265f20943996a22 to your computer and use it in GitHub Desktop.

Select an option

Save adentify/9a53eec0c2d69a18c265f20943996a22 to your computer and use it in GitHub Desktop.
PHP Delay response, handy for testing code dealing with slow responding sites.
<?php
header("Content-type: text/plain");
$payload = "";
// pass delay as param with length of 'd' in milliseconds
if(isset($_GET['delay'])){
$delay = $_GET['delay'];
if($delay > 30000){
$delay = 0;
$payload .= "// max timeout exceeded, we've set this as 0ms\n";
}
} else {
$delay = 2000;
}
usleep($delay*1000); // usleep works in microseconds, we pass d as milliseconds
if(isset($_GET['body'])){
$payload .= $_GET['body'];
} else {
$payload .= "var delaystatus = true;\n";
$payload .= "var delaytime = $delay; // milliseconds max = 30000";
}
print $payload;
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment