[PHP] Best way to manage open slots for download
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
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
[PHP] Basic question - Starting a background task without waiting for its end.
I (very simply) try to open a "notepad" on a simple text file in a simplistic PHP script, and would like to go on and display the next page without waiting for this notepad to be shut. After various attempts, I have used an : exec ('bash -c cmd /C start /MAX notepad "my_file" > NUL'); ... but it still wait for the shutting of the notepad ..! Could anybody help me ? For clarification : 1) I use this script on a machine which is in the same time "server" and "client", which gives "meaning" to this operation. 2) I use "bash -c" because I have the cygwin platform which can easily initiate tasks in background, but it could be suppressed, because it "de facto" changes nothing... Thank's for help. Michel. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Basic question - Starting a background task without waiting for its end.
Michel wrote: > > I (very simply) try to open a "notepad" on a simple text file in a > simplistic PHP script, and would like to go on and display the next page > without waiting for this notepad to be shut. > > After various attempts, I have used an : > > exec ('bash -c cmd /C start /MAX notepad "my_file" > NUL'); > > ... but it still wait for the shutting of the notepad ..! interesting question, I didn't really come up with an answer (maybe someone with real voodoo powers know the 'proper' answer) but I did find this page (which hopefully provides a useful work around [all kudos to the guy named Mike]): http://www.naken.cc/mikehup.php > > Could anybody help me ? > > For clarification : > 1) I use this script on a machine which is in the same time "server" and > "client", which gives "meaning" to this operation. > 2) I use "bash -c" because I have the cygwin platform which can easily > initiate tasks in background, but it could be suppressed, because it "de > facto" changes nothing... > > Thank's for help. > > Michel. > -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Script's length, echo, and execution speed
if performance/profiling this script is very important then take up the various suggestionms for doing just that - the only useful performance answer is the one you garner from your own testing (i.e. within your own env/setup) with regard to the 3500 lines of code (with 300 odd being run on any one request) and the fact that most of those lines are *very* simple echo statement I doubt very much you have *anything* to worry about with regard to performance. imho it sounds like your script is very simple and php will zip thru it like lightening. it's not unlikely if your running a big,complex application to run 100K+ LOC within a single request - the question is not so much how many LOC but how fast are those lines - obviously the power of your hardware play an integral part in determining what is exceptable/doable. with regard to 'optimizing' echo statements and keeping some kind of eye-pleasing formatting below are a couple of suggestions: Jean-Christophe Roux wrote: > Hello, > > I have this php script of 3,500 lines with a big switch that is such that on > each pass maybe 300 lines of codes are executed at most. The current speed > of the file is ok. I like to keep the file like that because at each pass > there is a check on the whole script and it fails if there is a typo > somewhere. Also, I like to have one file instead of many files. But I am > wondering if speed is not severaly hurt. What are the general guidelines in > terms > of length of script? > > Also, I am writing things like that: > echo ''; > echo ''; > echo "Content"; > echo ''; > echo ''; echo ' Boo! '; // OR $Content = 'Boo!'; echo '', '', "$Content", '', ''; -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: Basic question - Starting a background task without waiting for its end.
===ORIGINAL=== I (very simply) try to open a "notepad" on a simple text file in a simplistic PHP script, and would like to go on and display the next page without waiting for this notepad to be shut. After various attempts, I have used an : exec ('bash -c cmd /C start /MAX notepad "my_file" > NUL'); ... but it still wait for the shutting of the notepad ..! Could anybody help me ? For clarification : 1) I use this script on a machine which is in the same time "server" and "client", which gives "meaning" to this operation. 2) I use "bash -c" because I have the cygwin platform which can easily initiate tasks in background, but it could be suppressed, because it "de facto" changes nothing... ===END ORIGINAL=== php exec() waits for an output of command u passed. Also php does not have any threading support otherwise you could have run exec() in a seperate thread. Anyways! i think there is a work around for your problem! Create a seperate shell file, lets say abc.sh abc.sh run following command "bash -c cmd /C start /MAX notepad "my_file" > NULL" and exits you php file calls exec("abc.sh"); -- Regards Fahad Pervaiz www.ecommerce-xperts.com
[PHP] Request of php5
Dear All, Happy New Year, How much mem ( Ram ) does the php5 need ? Edward. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php