Re: [PHP] Best way to manage open slots for download

2007-01-02 Thread Richard Lynch
I think you want $bytes_out = $size, actually...

I'm not sure what you are sending out for that last extra byte... :-)

You could consider just timing out any zombies.

You could use ignore_user_abort and hope to finish most of the
downloads, as far as PHP is concerned, but I don't think
ignore_user_abort is 100% guaranteed, and there's always the chance of
a PHP or Apache connection crashing...

You could also re-think the problem to check, say, load on the server,
or some sort of bandwidth meter that you could manage, rather than N
slots.

So somebody on a dog-slow dialup downloading would not count as much
as somebody sucking down your entire bandwidth on a T-1.

By shaping it by the bytes/sec being spewed out by PHP, zombie
connections will naturally stop updating the meter, so won't count.

On Sun, December 31, 2006 9:12 am, Aras wrote:
 First of all, Happy New Year for everyone in the list. I wish 2007
 brings
 all us happiness, health and peace.

 I want to read your advises at a point i am stuck within, i have an
 application that serves downloads to clients. For some reason i am
 limiting
 total open slot for some group of users (not related to my technical
 question).

 Example;

 // CHECKS SLOT HERE

 else {  // IF THERE ANY AVAILABLE SLOTS SEND THE FILE

 // INCREMENT SLOT NUMBER BY 1

 $fp = fopen($pathside,r);

 if ($fp) {

   while (!feof($fp)) {
   echo fread($fp, 334);

   $bytes_out += 334;
   ob_flush();

   if ($bytes_out  $size) {

   // DECREASE SLOT NUMBER BY 1, BECAUSE THIS DOWNLOAD IS FINISHED

   }

   }

 }

 }


 Slots are recorded and checked from a simple mysql table. Everything
 works
 in this scenario. There is no problem if a person starts a download
 and
 finishes it, his slots get empty upon doing so. Yet if he cancelles
 the
 transfer, he will never reach my control structure to empty the slot.
 And
 slots will be full of zombies.

 I have thought of updating a mysql field for alive-connections in the
 while
 loop, but it will definitely add some load on my server. Updating a
 system
 file is not secure and good way.

 What other ways can you recommend to me for the situtation?


 Aras Koktas
 [EMAIL PROTECTED]
 Business Excellence Development
 Phi.dot Internet Systems

 --
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php




-- 
Some people have a gift link here.
Know what I want?
I want you to buy a CD from some starving artist.
http://cdbaby.com/browse/from/lynch
Yeah, I get a buck. So?

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Best way to manage open slots for download

2007-01-01 Thread tedd

At 10:15 AM -0500 12/31/06, Rasmus Lerdorf wrote:


  What other ways can you recommend to me for the situtation?

Read through this:

http://www.php.net/manual/en/features.connection-handling.php

-Rasmus


-Rasmus:

Just want to express my gratitude for your attendance to this list.

Thanks.

tedd

--
---
http://sperling.com  http://ancientstones.com  http://earthstones.com

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Best way to manage open slots for download

2006-12-31 Thread Aras
First of all, Happy New Year for everyone in the list. I wish 2007 brings
all us happiness, health and peace.

I want to read your advises at a point i am stuck within, i have an
application that serves downloads to clients. For some reason i am limiting
total open slot for some group of users (not related to my technical
question).

Example;

// CHECKS SLOT HERE

else {  // IF THERE ANY AVAILABLE SLOTS SEND THE FILE

// INCREMENT SLOT NUMBER BY 1

$fp = fopen($pathside,r);

if ($fp) {

while (!feof($fp)) {
echo fread($fp, 334);

$bytes_out += 334;
ob_flush();

if ($bytes_out  $size) {

// DECREASE SLOT NUMBER BY 1, BECAUSE THIS DOWNLOAD IS FINISHED

}

}

}

}


Slots are recorded and checked from a simple mysql table. Everything works
in this scenario. There is no problem if a person starts a download and
finishes it, his slots get empty upon doing so. Yet if he cancelles the
transfer, he will never reach my control structure to empty the slot. And
slots will be full of zombies.

I have thought of updating a mysql field for alive-connections in the while
loop, but it will definitely add some load on my server. Updating a system
file is not secure and good way.

What other ways can you recommend to me for the situtation?


Aras Koktas
[EMAIL PROTECTED]
Business Excellence Development
Phi.dot Internet Systems

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Best way to manage open slots for download

2006-12-31 Thread Rasmus Lerdorf
Aras wrote:
 First of all, Happy New Year for everyone in the list. I wish 2007 brings
 all us happiness, health and peace.
 
 I want to read your advises at a point i am stuck within, i have an
 application that serves downloads to clients. For some reason i am limiting
 total open slot for some group of users (not related to my technical
 question).
 
 Example;
 
 // CHECKS SLOT HERE
 
 else {  // IF THERE ANY AVAILABLE SLOTS SEND THE FILE
 
 // INCREMENT SLOT NUMBER BY 1
 
 $fp = fopen($pathside,r);
 
 if ($fp) {
 
   while (!feof($fp)) {
   echo fread($fp, 334);
 
   $bytes_out += 334;
   ob_flush();
 
   if ($bytes_out  $size) {
 
   // DECREASE SLOT NUMBER BY 1, BECAUSE THIS DOWNLOAD IS FINISHED
 
   }
 
   }
 
 }
 
 }
 
 
 Slots are recorded and checked from a simple mysql table. Everything works
 in this scenario. There is no problem if a person starts a download and
 finishes it, his slots get empty upon doing so. Yet if he cancelles the
 transfer, he will never reach my control structure to empty the slot. And
 slots will be full of zombies.
 
 I have thought of updating a mysql field for alive-connections in the while
 loop, but it will definitely add some load on my server. Updating a system
 file is not secure and good way.
 
 What other ways can you recommend to me for the situtation?

Read through this:

http://www.php.net/manual/en/features.connection-handling.php

-Rasmus

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php