doujiao0110 2014-07-10 10:38
浏览 325

使用PHP限制每个用户的服务器上传速度?

I have a situation where I need to be able to throttle / limit the upload speed (outgoing server connection) for each of my users using PHP. The reason why is because I'm running a small streaming website for my family and friends and currently each user can download data from the server at the users highest possible speed which causes other users to suffer due to lack of bandwidth on my server.

I did some calculations and I noticed that each user only need 1 Mbps to be able to stream movies from my server without any buffering.

So my question is:

How can I throttle / limit the servers upload speed per user using PHP?

I would be very happy if you could provide an example of how I can accomplish this, as of now I have no idea how i can do this.

  • 写回答

1条回答 默认 最新

  • dqx24298 2015-08-08 22:22
    关注

    You could use bandwidth-throttle/bandwidth-throttle

    use bandwidthThrottle\BandwidthThrottle;
    
    $in  = fopen(__DIR__ . "/resources/video.mpg", "r");
    $out = fopen("php://output", "w");
    
    $throttle = new BandwidthThrottle();
    $throttle->setRate(1, BandwidthThrottle::MIBIBYTES); // Set limit to 1MiB/s
    $throttle->throttle($out);
    
    stream_copy_to_stream($in, $out);
    
    评论

报告相同问题?

悬赏问题

  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)