]>
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
);
16 define('PHP_EXECUTABLE', '/usr/bin/php');
19 $last_checkpoint = -1;
21 function sigchld_handler($signal) {
23 if ($running_jobs > 0) $running_jobs--;
24 print posix_getpid() . ": SIGCHLD received, jobs left: $running_jobs\n";
25 pcntl_waitpid(-1, $status, WNOHANG
);
28 function sigint_handler() {
29 unlink(LOCK_DIRECTORY
. "/update_daemon.lock");
30 die("Received SIGINT. Exiting.\n");
33 pcntl_signal(SIGCHLD
, 'sigchld_handler');
34 pcntl_signal(SIGINT
, 'sigint_handler');
36 if (file_is_locked("update_daemon.lock")) {
37 die("error: Can't create lockfile. ".
38 "Maybe another daemon is already running.\n");
42 $lock_handle = make_lockfile("update_daemon.lock");
45 die("error: Can't create lockfile. ".
46 "Maybe another daemon is already running.\n");
49 while (true) { sleep(100); }
54 $next_spawn = $last_checkpoint + SPAWN_INTERVAL
- time();
56 if ($next_spawn %
10 == 0) {
57 print "[MASTER] active jobs: $running_jobs, next spawn at $next_spawn sec\n";
60 if ($last_checkpoint + SPAWN_INTERVAL
< time()) {
62 for ($j = $running_jobs; $j < MAX_JOBS
; $j++
) {
63 print "[MASTER] spawning client $j...";
66 die("fork failed!\n");
69 print "OK [$running_jobs]\n";
71 pcntl_signal(SIGCHLD
, SIG_IGN
);
72 pcntl_signal(SIGINT
, SIG_DFL
);
73 passthru(PHP_EXECUTABLE
. ' ' . CLIENT_PROCESS
);
77 $last_checkpoint = time();