From 02008cb19ac99727889cca05c7eddfbeef30d684 Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Wed, 23 Jan 2008 10:19:36 +0100 Subject: add multiprocess update daemon --- update_daemon2.php | 55 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 update_daemon2.php (limited to 'update_daemon2.php') diff --git a/update_daemon2.php b/update_daemon2.php new file mode 100644 index 000000000..3721a0979 --- /dev/null +++ b/update_daemon2.php @@ -0,0 +1,55 @@ +#!/usr/bin/php + 0) $running_jobs--; + print posix_getpid() . ": SIGCHLD received, jobs left: $running_jobs\n"; + pcntl_waitpid(-1, $status, WNOHANG); + } + + pcntl_signal(SIGCHLD, 'sigchld_handler'); + + while (true) { + + $next_spawn = $last_checkpoint + SPAWN_INTERVAL - time(); + + print "[MASTER] active jobs: $running_jobs, next spawn at $next_spawn sec\n"; + + if ($last_checkpoint + SPAWN_INTERVAL < time()) { + + for ($j = $running_jobs; $j < MAX_JOBS; $j++) { + print "[MASTER] spawning client $j..."; + $pid = pcntl_fork(); + if ($pid == -1) { + die("fork failed!\n"); + } else if ($pid) { + $running_jobs++; + print "OK [$running_jobs]\n"; + } else { + pcntl_signal(SIGCHLD, SIG_IGN); + passthru(CLIENT_PROCESS); + exit(0); + } + } + $last_checkpoint = time(); + } + sleep(1); + } + +?> -- cgit v1.2.3-54-g00ecf