Re: [PHP] Best way to manage open slots for download
- From: rasmus@xxxxxxxxxxx (Rasmus Lerdorf)
- Date: Sun, 31 Dec 2006 10:15:46 -0500
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
.
- References:
- Best way to manage open slots for download
- From: "Aras"
- Best way to manage open slots for download
- Prev by Date: Best way to manage open slots for download
- Next by Date: Basic question - Starting a background task without waiting for its end.
- Previous by thread: Best way to manage open slots for download
- Next by thread: Basic question - Starting a background task without waiting for its end.
- Index(es):