3 // This is an experimental multiprocess update daemon
4 // It consists of the master server (this file) and
5 // client batch script (update_daemon2_client.php) which
6 // should only be run by the server process
12 define('MAX_JOBS', 2);
13 define('CLIENT_PROCESS', './update_daemon2_client.php SRV_RUN_OK');
14 define('SPAWN_INTERVAL', DAEMON_SLEEP_INTERVAL);
17 $last_checkpoint = -1;
19 function sigchld_handler($signal) {
21 if ($running_jobs > 0) $running_jobs--;
22 print posix_getpid() . ": SIGCHLD received, jobs left: $running_jobs\n";
23 pcntl_waitpid(-1, $status, WNOHANG);
26 pcntl_signal(SIGCHLD, 'sigchld_handler');
30 $next_spawn = $last_checkpoint + SPAWN_INTERVAL - time();
32 print "[MASTER] active jobs: $running_jobs, next spawn at $next_spawn sec\n";
34 if ($last_checkpoint + SPAWN_INTERVAL < time()) {
36 for ($j = $running_jobs; $j < MAX_JOBS; $j++) {
37 print "[MASTER] spawning client $j...";
40 die("fork failed!\n");
43 print "OK [$running_jobs]\n";
45 pcntl_signal(SIGCHLD, SIG_IGN);
46 passthru(CLIENT_PROCESS);
50 $last_checkpoint = time();