1:
2: <?php
3: chdir(__DIR__);
4:
5: require_once('functions.php');
6:
7: if ($argc !== 2)
8: die("This command has to be called with exactly one(!) parameter: the path to the config file.\n");
9:
10: $configfile = $argv[1];
11:
12: set_error_handler("myErrorHandler");
13:
14: if (!stream_resolve_include_path($configfile))
15: die(sprintf("Missing config file: %s\n", $configfile));
16: require_once $configfile;
17:
18:
19: $supported_programs = unserialize(SUPPORTED_PROGRAMS);
20: $supported_programs_qmarks = implode(',', array_fill(0, count($supported_programs), '?'));
21:
22: while (true) {
23: $pdo = pdo_connect();
24: $stm_get_job = $pdo->prepare('SELECT * FROM request_job(?, ?, ARRAY[' . $supported_programs_qmarks . '])');
25: $stm_get_job->execute(array_merge(array(MAX_FORKS, HOSTNAME), array_keys($supported_programs)));
26: if ($stm_get_job->rowCount() > 0) {
27: $job = $stm_get_job->fetch(PDO::FETCH_ASSOC);
28:
29: unset($pdo, $stm_get_job);
30:
31:
32: if (function_exists('pcntl_fork')) {
33: $pid = pcntl_fork();
34: if ($pid == -1) {
35: die('forking failed! quitting.');
36: } else if ($pid) {
37:
38: continue;
39: } else {
40: include "worker-thread.php";
41: }
42: }
43:
44: else {
45: $tmpfile = tempnam(sys_get_temp_dir(), "worker");
46: file_put_contents($tmpfile, serialize(array('job'=>$job, 'configfile'=>$configfile)));
47: exec(sprintf('psexec -d php.exe worker-thread.php "%s"', $tmpfile));
48: }
49: } else {
50: usleep(5 * 1000 * 1000);
51: }
52: }
53:
54:
55:
56: function myErrorHandler($errno, $errstr, $errfile, $errline)
57: {
58: if (!(error_reporting() & $errno)) {
59:
60: return;
61: }
62: if ($errno == E_USER_NOTICE){
63: printf("Notice: %s in %s on line %d\n", $errstr, $errfile, $errline);
64:
65: return true;
66: }
67:
68: return false;
69: }
70: ?>