FRIHOST FORUMS SEARCH FAQ TOS BLOGS COMPETITIONS
You are invited to Log in or Register a free Frihost Account!


Running a script multiple times





polly-gone
Okay so lets say I have some sort of thing set up. And that thing uses some script to communicate with my web server. And that thing might send 10 requests per second. Does each request use its own copy of the script?

Like if I send one command and then 5 seconds later, another, but the script that processes the commands has a 10 seconds delay, will the second command process immediately or will it have to wait for that 10 seconds to be over?

Thanks,

-Nick Smile Smile Smile
jmraker
If the 2nd script waited for script 1 to finish, then the 2nd script would be waiting around for every other script to finish. Then it would be easy to shut down frihost or other sites by making scripts that sleep for a long time.

PHP does not wait automatically.

If php is running as an apache module, it depends on apache. I've often had servers that stop loading new pages until x number of requests (like downloads) are active.

If you need it to run something 1 at a time, you can use something like the code below

Code:
<?php
while(file_exists('lock.tmp')) // this is before any processing
   sleep(1);
touch('lock.tmp');      // create lock so only this code is running
echo "Start\n";

sleep(10);
// Do processing stuff

unlink('lock.tmp');     // release lock so another copy can run
echo "Done\n";
?>


Keep in mind that PHP programs exit after so much time (default is 30 seconds) and it may exit while waiting (a request is lost). Also if the processing ever abnormally ends, it'll leave the lock.tmp and nothing will run, so something more than a file_exists is necessary. Plus the code above doesn't run the requests in order if there's more than 1 waiting.
polly-gone
I'm talking about if one files can be run more than one at the same time.

For example form.php submits to formProcess.php.

formProcess.php processes the form data then sleeps for 2 minutes and then submits it to a database. Now the script is still running for that two minutes.

Well someone goes in and submits another form within 10 seconds of the first. When it gets to formProcess.php, it is only 10 seconds into its sleep. Is it going to be another 110 seconds before the new form data is processed or does that new data open up its own instance of formProcess.php?

Thanks,

-Nick Smile Smile Smile
imagefree
polly-gone wrote:
I'm talking about if one files can be run more than one at the same time.

For example form.php submits to formProcess.php.

formProcess.php processes the form data then sleeps for 2 minutes and then submits it to a database. Now the script is still running for that two minutes.

Well someone goes in and submits another form within 10 seconds of the first. When it gets to formProcess.php, it is only 10 seconds into its sleep. Is it going to be another 110 seconds before the new form data is processed or does that new data open up its own instance of formProcess.php?

Thanks,

-Nick Smile Smile Smile



Yes scripts run on simultaneous requests. For example if you have 2 simultaneous requests, server starts processing both requests as they are received.

The above fact doesnt apply when you are using sessions (used session_start()). PHP locks up session files when read by one request and the second request waits for its getting free. (there are however solution to avoid this).
Agent ME
I'm pretty sure you can have several sessions running concurrently.
polly-gone
Alright, thank you. I am currently working on something that will GET and POST alot to certain scripts and I don't want them to get backed up.

-Nick Smile Smile Smile
Related topics
Capturing multiple USB cams to an AVI or MPEG file.
Windows Vista Official Thread
Tutorial: Image Rollovers w/ Javascript
How much Bandwidth/Transfer does Google Use???
how can i catch onkeydown event when using frameset
StarGate Fans ?????
How long your windows is working without reinstall?
A Winner is not only who never fails !!!! But never quits !!
Best Gaming System is best
Cop Shot at Several Times
Windows XP SP3 comming soon
How To Use the Header() function
multiple mysql connections
monument problems
Reply to topic    Frihost Forum Index -> Scripting -> Php and MySQL

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.