]>
git.wh0rd.org - tt-rss.git/blob - update_daemon2.php
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
10 require_once "config.php";
11 require_once "functions.php";
13 define('MAX_JOBS', 2);
14 define('CLIENT_PROCESS', './update_daemon2_client.php SRV_RUN_OK');
15 define('SPAWN_INTERVAL', DAEMON_SLEEP_INTERVAL
);
18 $last_checkpoint = -1;
20 function sigchld_handler($signal) {
22 if ($running_jobs > 0) $running_jobs--;
23 print posix_getpid() . ": SIGCHLD received, jobs left: $running_jobs\n";
24 pcntl_waitpid(-1, $status, WNOHANG
);
27 function sigint_handler() {
28 unlink(LOCK_DIRECTORY
. "/update_daemon.lock");
29 die("Received SIGINT. Exiting.\n");
32 pcntl_signal(SIGCHLD
, 'sigchld_handler');
33 pcntl_signal(SIGINT
, 'sigint_handler');
35 if (file_is_locked("update_daemon.lock")) {
36 die("error: Can't create lockfile. ".
37 "Maybe another daemon is already running.\n");
41 $lock_handle = make_lockfile("update_daemon.lock");
44 die("error: Can't create lockfile. ".
45 "Maybe another daemon is already running.\n");
48 while (true) { sleep(100); }
53 $next_spawn = $last_checkpoint + SPAWN_INTERVAL
- time();
55 if ($next_spawn %
10 == 0) {
56 print "[MASTER] active jobs: $running_jobs, next spawn at $next_spawn sec\n";
59 if ($last_checkpoint + SPAWN_INTERVAL
< time()) {
61 for ($j = $running_jobs; $j < MAX_JOBS
; $j++
) {
62 print "[MASTER] spawning client $j...";
65 die("fork failed!\n");
68 print "OK [$running_jobs]\n";
70 pcntl_signal(SIGCHLD
, SIG_IGN
);
71 pcntl_signal(SIGINT
, SIG_DFL
);
72 passthru(CLIENT_PROCESS
);
76 $last_checkpoint = time();