PHP: output very slowly

I want to imitate a very slow server.

How can I make PHP send output very slowly?  I want it to send a few bytes then sleep then send a few more bytes.

$image = 'image.png';

header('HTTP/1.1 200 OK', true);
header('Content-Length: ' . filesize($image) , true);
header('Content-Type: image/png', true);
header('Content-Disposition: inline; filename="image1.png"', true);
header('X-Powered-By: XYZ Digital Asset Management', true);
header("Cache-Control: no-cache, must-revalidate", true);
header("Expires: Sat, 26 Jul 1997 05:00:00 GMT", true);
header('Cache-Control: private', true);




Open in new window

LVL 16
Who is Participating?
Rik-LeggerConnect With a Mentor Commented:
$fh = fopen($local_file, "r");
    // output file without bandwidth limiting
    print(fread($fh, 51200)); // 51200 bytes = 50 kB

Open in new window

Should have a speedlimit of 50kbps
bartvdConnect With a Mentor Commented:
replace readfile($image); with:

$fh = fopen($image, 'r');
$theData = fread($fh, filesize($$image));

echo substr($theData,(i*filesize($$image))/100,filesize($$image))/100);
time_nanosleep(0, 100000);

This will split the file in 100 pieces and wait 0.1 sec between them
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.