douhui0975 2015-12-13 04:23 采纳率: 100%
浏览 89
已采纳

PHP file_put_contents设置速度限制

I try to download big file from url to my server, but I need to set download speed limit, for example 100kb/s.

This is my code:

<?php
    $random = rand(00000000,999999999);
    $file_url = "BIG FILE URL";

    $get_name = basename($file_url);
    $file_new_name = $random.$get_name;

    $get_file = file_get_contents($file_url);
    $put_file = file_put_contents($file_new_name, $get_file);

    if( $put_file ){
        echo "Done!";
    }
?>

Code is working but fast speed! I need speed to be 100kb/s.

  • 写回答

1条回答 默认 最新

  • douling6469 2015-12-13 04:40
    关注

    You can try mod_bandwidth or more advanced mod_cband.

    Quote from mad_bandwidth site:

    Mod_bandwidth is a module for the Apache webserver that enable the setting of server-wide or per connection bandwidth limits, based on the directory, size of files and remote IP/domain.

    Quote from mod_cband site:

    mod_cband is an Apache 2 module provided to solve the problem of limiting users’ and virtualhosts’ bandwidth usage. The current versions can set virtualhosts’ and users’ bandwidth quotas, maximal download speed (like in mod_bandwidth), requests-per-second speed and the maximal number of simultanous IP connections (like in mod_limitipconn)

    Here is tutorial about how to use cband to limit download speed.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 关于大棚监测的pcb板设计
  • ¥20 sim800c模块 at指令及平台
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用
  • ¥15 C++ yoloV5改写遇到的问题
  • ¥20 win11修改中文用户名路径
  • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入
  • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计