Hello,

This is the situation: I have a script that works off each entry in a
database... 3 entries are made every minute (aproximately). And the
script takes aprox. 1 Minute to finishup each entry. So I need to start
a couple of instances of this script... I want to start 21 instances
once every hour to work off the load that has built up in the past hour.
The script enter it's current pid and starting time in a seperate table.
If a process takes more then three minutes => kill it and start that
request over... I made a parent script to do the "calling-up" and the
(if neccessary) "killing" of the child scripts.
The problem is it does not call up 21 instances of the child script
instead it calls up one and apparently waits for the child script to get
done (and die) and then continues... I actually just want the parent
script to start the child script and abandon it... regardless of the
child's output... 
A second wierd phanomenon is that the parent-script goes into a coma...
and seems to not continue in the while-loop after aprox. 2 hours of
being executed. Eventhough this QUERY: mysql_result(mysql_query("SELECT
count(nr) AS needy FROM Clients WHERE done = '0'"),0,"needy") returns a
value far from 0... The only assumtion I could have is  since the parent
script is waiting for the child script to die... which it is not (it got
hung up)... then it can't kill it and waits and waits and waits.
The table is called "control"... a sample entry is like the following:

nr   | cur_pid |cur_time     | cur_client_nr
110 |  4919   | 986776912 |  9190            

I am using the CGI-Version of PHP and teh max_timeout of PHP has been
set to "0". Another something that might help in finding the solution is
when I enter in the commandline "php -q post.client.php &" I recieve
only this feedback:
[2] 5656 (the processnumber)

I have even tried calling up a bash script which itself calls up the
script without printing and info instead of the script itself... but
this does not work either the parent script waits for the child to die
before continuning... 

My ideal vision of what this script could be. Would be a process that
runs un-end constantly checking if there is something to be done... if
so that to start the neccessary processes... Ultimatly all I would have
to do is to make the primary while statment something like while (1!=2)
{...} right?... But then there is the problem of the comatosing script

This is the parent script:

//////////////////////////START OF CODE//////////////////////
$poster_name = "control.lock";
if(!@fopen($poster_name, "r")) {$fd = @fopen($poster_name, "w");
fputs($fd, posix_getpid()); fclose($fd);

// Connect to the Database
mysql_pconnect("localhost","root","****") or die("Unable to connect to
SQL server");
mysql_select_db("******") or die("Unable to select database");

// Check if Clients need submitting
 while (mysql_result(mysql_query("SELECT count(nr) AS needy FROM Clients
WHERE done = '0'"),0,"needy") != 0) {

 // Kill all Zombie Processes
 $overdo = mysql_query("SELECT * FROM control WHERE cur_time <
(UNIX_TIMESTAMP()-180)");
 if (mysql_num_rows($overdo) != 0) {
  while ($overdone = mysql_fetch_array($overdo)) {
   //echo "KILLING PID ". $overdone["cur_pid"];
   @posix_kill($overdone["cur_pid"],"9");
   mysql_query("UPDATE Clients SET done = '0' WHERE nr = '" .
$overdone["cur_client_nr"] . "'");
   mysql_query("DELETE FROM control WHERE nr='". $overdone["nr"] ."'");
   mail("[EMAIL PROTECTED]","ZOMBIE ERROR", "ZOBIE at " . date("D M j
g:i:s T Y") ." \nClient_Nr: ".$overdone["cur_client_nr"]."\n");
   
  }
 }
 // Check if Processes are possible
 if (mysql_result(mysql_query("SELECT count(nr) AS num_proc FROM
control"),0,"num_proc") < 21) {
  //echo "Starting Process!";
  exec("php -q post.client.php &");
 }
 
} // END While Client "needy"

 
// Ganz zum Schluß die LOCK-Datei löschen
exec("rm -f " . $poster_name);
//echo "Removing Lock";
} else { // END OF IF for duplicate running
//echo "Already running";
}
//////////////////////////END OF CODE//////////////////////

Thanks for your help in advance...
Joe..

Reply via email to