PHP: output very slowly

Posted on 2011-05-05
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.

$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

Question by:hankknight
    LVL 8

    Accepted Solution

    $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
    LVL 6

    Assisted Solution

    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

    Featured Post

    Maximize Your Threat Intelligence Reporting

    Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

    Join & Write a Comment

    Suggested Solutions

    This is a general how to create your own custom plugin system for your PHP application that you designed (or wish to extend a third party program to have plugin functionality that doesn't have it yet).  This is not how to make plugins for existing s…
    Introduction Many web sites contain image galleries; a common design for these galleries includes a page with a collection of thumbnail images.  You can click on each of the thumbnail images to see the larger version of the image.  This is easily i…
    The viewer will learn how to count occurrences of each item in an array.
    The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

    754 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

    Need Help in Real-Time?

    Connect with top rated Experts

    16 Experts available now in Live!

    Get 1:1 Help Now