Not sure if anyone is interested in what I have come up with, its busy running just now but it seems to be performing ok.
$do =0; $ok =0; $count=0; while($do!=1){ if($ok==0){ $sql = "SELECT * FROM locations WHERE parent = '0' AND doing=0 and done !=1 ORDER BY num DESC LIMIT 0 , 1"; $res = mysql_query($sql) or die ($sql.mysql_error()); while($_data = mysql_fetch_array($res)){ $id = $county_data["id"]; $sql2 = "UPDATE locations SET doing = 1 WHERE id= '$id' AND siteid=1 AND parent = '0'"; $res3 = mysql_query($sql2); exec("/usr/local/bin/php fork.php ".$data["id"]." > /dev/null &"); } } $sql = "SELECT * FROM locations WHERE parent = '0' AND doing=1 AND done=0"; $res = mysql_query($sql); $oknumber = mysql_num_rows($res); if($oknumber == 5) $ok=1; else $ok=0; $sql = "SELECT * FROM locations WHERE parent = '0' AND done=0"; $res2 = mysql_query($sql); $donumber = mysql_num_rows($res2); if($donumber==0) $do=1; } In my fork.php script I set it to done=1 and doing = 0 once it has finished. This is pretty rough and ready and as my shell account won't let me do a "top" i can't tell what sort of drain my loop is having on the system, but hopefully it will be ok. Just thought it might be an idea to post up this solution in-case someone else has the same problem. John On Mon, 2004-09-20 at 16:36, John Wards wrote: > 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 &"); > } > > Cheers > John Wards -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php