?
Solved

PHP: output very slowly

Posted on 2011-05-05
2
Medium Priority
?
294 Views
Last Modified: 2012-05-11
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.
<?php 

$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);

readfile($image);

exit;

?>

Open in new window

0
Comment
Question by:hankknight
2 Comments
 
LVL 8

Accepted Solution

by:
Rik-Legger earned 1600 total points
ID: 35699660
$fh = fopen($local_file, "r");
while(!feof($fh)) 
{
    // output file without bandwidth limiting
    print(fread($fh, 51200)); // 51200 bytes = 50 kB
    sleep(1);
}

Open in new window


Should have a speedlimit of 50kbps
0
 
LVL 6

Assisted Solution

by:bartvd
bartvd earned 400 total points
ID: 35699714
replace readfile($image); with:

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

for($i=0;$i<100;$i++)
{
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
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
This article discusses four methods for overlaying images in a container on a web page
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
Suggested Courses
Course of the Month14 days, 22 hours left to enroll

840 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question