Limit bandwidth speed with PHP

Posted on 2009-04-20
Last Modified: 2012-05-06
My server is now delevering downloads at 1 Mb/s.  That is way to fast and I want to slow this down to 20 1 Kb/s.

How can I do this?

$file = '';

if (file_exists($file)) {

    header('Content-Description: File Transfer');

    header('Content-Type: application/octet-stream');

    header('Content-Disposition: attachment; filename='.basename($file));

    header('Content-Transfer-Encoding: binary');

    header('Expires: 0');

    header('Cache-Control: must-revalidate, post-check=0, pre-check=0');

    header('Pragma: public');

    header('Content-Length: ' . filesize($file));







Open in new window

Question by:hankknight
    LVL 16

    Assisted Solution

    by:Chris Harte
    You cannot do this with php.
    This has to be done on the server.
    Here is a link to show how it can be done on Apache

    LVL 16

    Author Comment

    More creativity, please.  This can be done with PHP!  Send a few bytes, sleep, send a few more bytes, sleep, ect.

    What is the most resource efficient way to do this?
    LVL 10

    Accepted Solution

    Sure this can be done with php if your goal is to rewrite QoS using PHP. In any account i dont think this solution will be anything near to "Whats the most efficient way to do this"

    When making a sidestep on the subject, and you are trying to recreate something like this..
    Then your approach is a off ;-). In that case you need something like this...

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Free Trending Threat Insights Every Day

    Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

    Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
    Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
    The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
    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…

    779 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

    14 Experts available now in Live!

    Get 1:1 Help Now