制作一个特殊的下载页面[关闭]

I want to create a download page.And I want to offer two kinds of download option for users:

->Download from fast server(users pay 1 dollar to download and download at full speed)

->Download from slow server(free but download speed should be 70-100kb/s)

I am a newbie and I will be glad if anyone can explain me how to: 1)Put a download speed limit 2)make free and premium subscription for users while keeping in mind that the free users get low speed 3)integrating paypal as a payment method for premium users Any help would be appreciated.

Thanks in advance

What you're looking for is called mod_ratelimit for Apache httpd, or the limit_rate directive for nginx.

Don't rely on PHP to handle the entire download process for you since you'd be tying up an entire PHP worker for no added benefit. Instead, you can rely on using PHP to handle the authentication mechanism of subjugating the download URI and then use X-SENDFILE headers with Apache httpd mod_xsendfile, for example, to handle the actual download.

This would be as simple as doing something like the following in your PHP...

<?php
session_start();
if ($_SESSION['authed']) {
    header("X-SENDFILE: /path/to/download/foo.zip");
} else {
    header('Location: /authenticate');
}

Some of the benefits you get from relying on the webserver to serve up the file for you include:

  • Optimal delivery (takes advantage of mmap where available)
  • Processes cache headers correctly (as if the file were served up statically)
  • Doesn't tie up your PHP process for the duration of the download, making it available to serve up other requests that really do need PHP for something other than delivering static content.

You could output file to browser in chunks and use sleep() function to limit speed. For example you output like 256 kB and then sleep(1) for 1s

Also check this link Apache - how to limit maximum download speed of files? (if not apache, i can run lighthttpd)

I think that @Sherif suggestion to use http server is better.