Running multiple instances of a PHP script

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
anjanesh
DevNet Resident
Posts: 1679
Joined: Sat Dec 06, 2003 9:52 pm
Location: Mumbai, India

Running multiple instances of a PHP script

Post by anjanesh »

Hi

I have a script - run.php which does some long running task - this takes hours to complete.

I tried to open a new window with run.php but it doesnt seem to start until the other one is finished. Instead - if I make a copy of it say run1.php it works fine - obviously - because they are 2 different scripts. But the code reads/writes data to a MySQL database which takes places once in a few mins - the mysql access part is not resource intensive.

Is there any way for me to get run.php running simultaneously in say 10 browser windows ?
Not running on this localhost - running this on the server - in the form of a url.

Thanks
User avatar
protokol
Forum Contributor
Posts: 353
Joined: Fri Jun 21, 2002 7:00 pm
Location: Cleveland, OH
Contact:

Post by protokol »

Does this script simply process data in the background and not actually display anything on the web page? If so, then you might considure the Process Control Functions.

http://www.php.net/pcntl

They are a nice way to fork processes to handle multiple tasks simultaneously.
User avatar
anjanesh
DevNet Resident
Posts: 1679
Joined: Sat Dec 06, 2003 9:52 pm
Location: Mumbai, India

Post by anjanesh »

Well...it doesnt really need to display anything - but I've given an echo statement in the loop so that I can see the progress.
If I didnt want it to display anything then I would've set it in cron.
Post Reply