Last active
August 29, 2015 14:24
-
-
Save wouterds/c0323f90ca8301b480b6 to your computer and use it in GitHub Desktop.
Simulate slow downloads. Usage: slow-downloader.php?path=static/videos/intro.mp4
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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