Re: PHP bandwidth control
| From: | JD | Date: | Tue, 07 Apr 2009 14:36:08 +0000 |
| Subject: | Re: PHP bandwidth control | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-291176@lists.php.net to get a copy of this message | ||
Awesome, you guys rock! Now I have a bunch of stuff to play around with and the more I read about
these functions and try playing around with them the more I think I'll learn about this stuff.
This is great! Thanks again!
---------- Original Message ----------
From: Yannick Mortier <mvmortier@googlemail.com>
To: Chris <dmagick@gmail.com>
Cc: JD <danceintherain82@netzero.com>, php-general@lists.php.net
Subject: Re: [PHP] PHP bandwidth control
Date: Tue, 7 Apr 2009 10:42:01 +0200
2009/4/7 Chris <dmagick@gmail.com>:
>
>> I guess there are multiple ways to engage this problem. It depends how
>> "deep" you want to log the traffic. If you just want to count the
>> traffic of each image, video etc you could just wrap up each image and
>> video to go through php first with file_get_contents() (look in the
>> php manual there are some examples how to work with this), count how
>> many bytes of data will be sent out and log this in a database or
>> however you want to do this.
>
> While it's a good suggestion, don't use file_get_contents because it reads
> the whole file in to memory.
>
> If you use it on a 200Meg movie, it uses > 200Meg of memory.
>
> Use filesize() to work out the size.
>
> Then use fpassthru to shove the data through.
>
> http://www.php.net/fpassthru
>
> --
> Postgresql & php tutorials
> http://www.designmagick.com/
>
>
Just another small addition I just got from the php manual:
You can use readfile() instead of fpassthru() so you don't have to use fopen().
pseudo code updated:
if ( used_bandwith + filesize > allowed_bandwidth)
error_message()
else
write_in_database(used_bandwith = used_bandwith + filesize)
readfile(file)
Theres always something to learn in PHP Land.
--
Currently developing a browsergame...
http://www.p-game.de
Trade - Expand - Fight
Follow me on twitter!
http://twitter.com/moortier
____________________________________________________________
Come clean with a brand new shower. Click now!
http://thirdpartyoffers.netzero.net/TGL2231/fc/BLSrjnxSDIEW3SA42CWj9n1jKPvjPfebqCKiqTbwOunnXNFT7dskjTO8Tmg/