Re: Fork PHP script X at a time.

From: Date: Mon, 20 Sep 2004 15:45:00 +0000
Subject: Re: Fork PHP script X at a time.
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-197301@lists.php.net to get a copy of this message
> Hi, I have a bit of a cold today so I probably would have figured this > out for myself eventually but hey ;-) > > Right I have a script that I need to run around 90 times thru a cron job > but passing a different i.d. to it each time. > > I have experimented with running all 90 at once and its a no go as it > just makes the server run to slow and the session cookies I use time out > (I am doing some libcurl things). > > Also running them in a loop one at a time is no use because it takes > about 8 hours. > > What I would like to do is fork off say 5-10 at a time and when one is > done start another one in its place, as they all take different length > of times to compleate. > > Any clues at where to start? Here is my fork all 90+ code... > > $sql = "SELECT * FROM locations WHERE parent = '0'"; > $res = mysql_query($sql) or die ($sql.mysql_error()); > while($data = mysql_fetch_array($res)){ > exec("/usr/local/bin/php fork.php ".$_data["id"]." > > /dev/null &"); > } You should be able to find out about the PID's for every forked process, and use a loop (advisable with a sleep() in it) to see how many procs are still running.. When the amount drops somewhat, spawn another .. Hope will get you somewhere!

« previous php.general (#197301) next »