473,386 Members | 1,758 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

forking multiple processes at a time

i have a php script that needs to execute an external php script (call this
script 2) when the user clicks a link, however I don't want the user to have
to wait until script 2 finishes executing before he sees the output of
script one... i know I can use the exec() command to do this, and use the &
to run the command in the background....

but say i want to run 100 instances of script 2 when the user clicks the
link (with different arguments)... i dont want to have all 100 processes
running at the same time... what I would like to do is run 10 or so at once,
and once those 10 are completed, run another 10...

how would i accomplish this?
Jul 17 '05 #1
4 2769
SomeGei wrote:
i have a php script that needs to execute an external php script (call this
script 2) when the user clicks a link, however I don't want the user to have
to wait until script 2 finishes executing before he sees the output of
script one... i know I can use the exec() command to do this, and use the &
to run the command in the background....

but say i want to run 100 instances of script 2 when the user clicks the
link (with different arguments)... i dont want to have all 100 processes
running at the same time... what I would like to do is run 10 or so at once,
and once those 10 are completed, run another 10...

how would i accomplish this?


Could the last process of each batch launch the next 10 processes?

Another approach is using cron and having script 1 store in a file the
arguments for the 100 instances of script 2. cron would run a "launcher"
every minute, and this launcher would execute a copy of script 2 for
each set of arguments in the file.

Jul 17 '05 #2
SomeGei wrote:
i dont want to have all 100 processes running at the same time...
what I would like to do is run 10 or so at once,
and once those 10 are completed, run another 10...

how would i accomplish this?


Check out popen() and related functions
http://www.php.net/popen

<?php // basic code with no error-checking
for ($i=0; $i<10; ++$i) {

/* open ten processes */
for ($j=0; $j<10; ++$j) {
$pipe[$j] = popen('script2.php', 'w');
}

/* wait for them to finish */
for ($j=0; $j<10; ++$j) {
pclose($pipe[$j]);
}
}
?>
--
Mail to my "From:" address is readable by all at http://www.dodgeit.com/
== ** ## !! ------------------------------------------------ !! ## ** ==
TEXT-ONLY mail to the whole "Reply-To:" address ("My Name" <my@address>)
may bypass my spam filter. If it does, I may reply from another address!
Jul 17 '05 #3

"SomeGei" <so**@gei.com> wrote in message
news:qJ********************@giganews.com...
i have a php script that needs to execute an external php script (call this script 2) when the user clicks a link, however I don't want the user to have to wait until script 2 finishes executing before he sees the output of
script one... i know I can use the exec() command to do this, and use the & to run the command in the background....

but say i want to run 100 instances of script 2 when the user clicks the
link (with different arguments)... i dont want to have all 100 processes
running at the same time... what I would like to do is run 10 or so at once, and once those 10 are completed, run another 10...

how would i accomplish this?


Have each instance of the program spawn a copy of itself when it finishes.
Jul 17 '05 #4
SomeGei wrote:
i have a php script that needs to execute an external php script (call this script 2) when the user clicks a link, however I don't want the user to have to wait until script 2 finishes executing before he sees the output of script one... i know I can use the exec() command to do this, and use the & to run the command in the background....

<snip>

http://in.php.net/system
<quote>
Note: If you start a program using this function and want to leave it
running in the background, you have to make sure that the output of
that program is redirected to a file or some other output stream or
else PHP will hang until the execution of the program ends.
</quote>

--
<?php echo 'Just another PHP saint'; ?>
Email: rrjanbiah-at-Y!com Blog: http://rajeshanbiah.blogspot.com/

Jul 17 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Eric S. Johansson | last post by:
I was working on a filter for postfix and instead of using the "fork a new python process on every message" route, I decided to use the SMTP interface instead and try forking after having started...
9
by: JennaS | last post by:
Hi. I was just wondering if you can fork a process in .NET like you would in C Thank Jenna
3
by: felixfix | last post by:
Hi all, I am just wondering if something is wrong with my program. What it bascially does is to output a fibonacci sequence base on the command-line output. If I give a 5, it will generate the...
9
by: Abhishek Srivastava | last post by:
Hello All, In IIS 6.0 We have a concept of worker processes and application pools. As I understand it, we can have multiple worker process per appliction pool. Each worker process is dedicated...
5
by: Jeremy | last post by:
I have a core VB service that monitors a database, and based on data in the records will execute code to send email notifications. Problem: I don't want my main program code to halt and wait for...
9
by: Andrew Robert | last post by:
Hi everyone, I have a python program that will need to interact with an MQSeries trigger monitor. It does this fine but it hogs the trigger monitor while it executes. I'd like to fork the...
3
by: czajnik | last post by:
Hi! I'm quite new to Python development. Can someone advise me a framework useful for building (pre-)forking or threaded TCP servers, other than SocketServer ? I've seen source code of a few...
10
by: qwertycat | last post by:
I'm new to multi-process programming, should one avoid forking children from children of a parent? I'd like to spawn 10 children from the parent and each of those children spawns another 5...
3
by: Scottman | last post by:
I am writing a server daemon that forks a child for every incoming request. The child process terminates when the client closes the connection. My problem is that I am unsure how to prevent the...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.