Skip to content

Instantly share code, notes, and snippets.

@wouterds
Last active August 29, 2015 14:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wouterds/c0323f90ca8301b480b6 to your computer and use it in GitHub Desktop.
Save wouterds/c0323f90ca8301b480b6 to your computer and use it in GitHub Desktop.
Simulate slow downloads. Usage: slow-downloader.php?path=static/videos/intro.mp4
<?php
// 128KB/100ms
$ms = 100;
$size = 128;
$path = $_GET['path'];
if (empty($path)) {
return;
}
$fileContents = file_get_contents($path);
$finfo = finfo_open(FILEINFO_MIME_TYPE);
$contentType = finfo_file($finfo, $path);
$contentLength = strlen($fileContents);
header('Content-Length: ' . $contentLength);
header('Content-Type: ' . $contentType);
$increment = 1024 * $size;
for ($i = 0; $i <= $contentLength; $i += $increment) {
echo substr($fileContents, $i, $increment);
usleep(1000 * $ms);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment