php-general Digest 1 Jan 2007 06:42:20 -0000 Issue 4544
Topics (messages 246304 through 246309):
Re: Best way to manage open slots for download
246304 by: Rasmus Lerdorf
Basic question - Starting a background task without waiting for its end.
246305 by: Michel
246306 by: Jochem Maas
246308 by: Fahad Pervaiz
Re: Script's length, echo, and execution speed
246307 by: Jochem Maas
Request of php5
246309 by: edwardspl.ita.org.mo
Administrivia:
To subscribe to the digest, e-mail:
[EMAIL PROTECTED]
To unsubscribe from the digest, e-mail:
[EMAIL PROTECTED]
To post to the list, e-mail:
[email protected]
----------------------------------------------------------------------
--- Begin Message ---
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
--- End Message ---
--- Begin Message ---
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.
--- End Message ---
--- Begin Message ---
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.
>
--- End Message ---
--- Begin Message ---
===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
--- End Message ---
--- Begin Message ---
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 '<table>';
> echo '<tr>';
> echo "<td>Content</td>";
> echo '</tr>';
> echo '</table>';
echo '<table>
<tr>
<td>Boo!</td>
</tr>
</table>';
// OR
$Content = 'Boo!';
echo '<table>',
'<tr>',
"<td>$Content</td>",
'</tr>',
'</table>';
--- End Message ---
--- Begin Message ---
Dear All,
Happy New Year,
How much mem ( Ram ) does the php5 need ?
Edward.
--- End Message ---