The Little Guy
03-17-2006, 11:18 PM
Is it possible using PHP to set bandwidth limits to certain files?
|
Click to See Complete Forum and Search --> : directory bandwidth limits The Little Guy 03-17-2006, 11:18 PM Is it possible using PHP to set bandwidth limits to certain files? BuezaWebDev 03-18-2006, 03:26 AM Hrmm--there's probably a more simpler way of doing this, but this is what I would do: [1] create a php file that uses parameters to reference the specific file you want to monitor bandwidth for. [2] everytime a request is generated for that file, have a table in the database that stores how many times it's been downloaded. [3] set a maximum amount of requests in the php file, and simply query the db and check if that file has been downloaded X amount of times--if so, echo "File has reached it's maximum bandwidth." There's probably an easier way of doing this--but that's my 2 cents. bathurst_guy 03-18-2006, 04:27 AM I doubt there is actually a php function that does this - you would have to do something like Bueza described bokeh 03-18-2006, 05:56 AM Hrmm--there's probably a more simpler way of doing this, but this is what I would do: [1] create a php file that uses parameters to reference the specific file you want to monitor bandwidth for. [2] everytime a request is generated for that file, have a table in the database that stores how many times it's been downloaded. [3] set a maximum amount of requests in the php file, and simply query the db and check if that file has been downloaded X amount of times--if so, echo "File has reached it's maximum bandwidth." There's probably an easier way of doing this--but that's my 2 cents.What's that got to do with measuring bandwidth? The method you describe would measure data transfer not bandwidth. To limit bandwidth (not data transfer) do something like this:function limitBandwith($filename, $speed = 10 /* kilobytes/sec */) { ob_start(); include($filename); $now = time(); foreach(str_split(ob_get_clean(), $speed*1024) as $chunk) { echo $chunk; flush(); $now++; while($now > time()) { usleep(100000); } } }This could be made smoother with shorter time increments. webdeveloper.com
Copyright Internet.com Inc., All Rights Reserved. |