4 $MESSAGE_KEY = ftok(realpath(dirname(__FILE__)), "c"); // to daemon
5 $LOCKING_KEY = ftok(realpath(dirname(__FILE__)), "l");
6 $STORE_KEY = ftok(realpath(dirname(__FILE__)), "s");
7 $CONF_STORE_SIZE = 16777216; // 16M by default
9 global $MESSAGE_KEY, $LOCKING_KEY, $STORE_KEY, $CONF_STORE_SIZE;
12 function __construct()
14 global $MESSAGE_KEY, $LOCKING_KEY, $STORE_KEY;
15 $this->semres = sem_get($LOCKING_KEY, 0666);
16 $this->msgres = msg_get_queue($MESSAGE_KEY, 0666);
19 function getConfig($type=0)
21 global $MESSAGE_KEY, $LOCKING_KEY, $STORE_KEY, $CONF_STORE_SIZE;
22 sem_acquire($this->semres);
23 $shm_space = shm_attach($STORE_KEY, $CONF_STORE_SIZE);
24 $config = shm_get_var($shm_space, $type);
25 sem_release($this->semres);
30 function lockConfigs()
32 sem_acquire($this->semres);
35 function unlockConfigs()
37 sem_release($this->semres);
40 function deleteConfig($type)
42 global $MESSAGE_KEY, $LOCKING_KEY, $STORE_KEY, $CONF_STORE_SIZE;
43 $shm_space = shm_attach($STORE_KEY, $CONF_STORE_SIZE);
45 shm_remove_var($shm_space, $type);
48 // type = 0 for the fs config
49 // type = 1 for the boot hardware config
50 // type = 2 for running config
51 // type = 3 for web config
53 // type = 4 for merged running config cache
54 // type = 5 for merged web config cache
56 // type = 6 for "messages" that appear on the pages
57 function putConfig($config, $type=0)
59 global $MESSAGE_KEY, $LOCKING_KEY, $STORE_KEY, $CONF_STORE_SIZE;
60 sem_acquire($this->semres);
61 $shm_space = shm_attach($STORE_KEY, $CONF_STORE_SIZE);
62 shm_put_var($shm_space, $type, $config);
63 sem_release($this->semres);
66 function waitForMessage()
68 global $MESSAGE_KEY, $LOCKING_KEY, $STORE_KEY;
69 $queue = msg_get_queue($MESSAGE_KEY);
70 msg_receive($queue, 0, $msgtype, 1024, $msg);
75 function sendMessage($msg)
77 global $MESSAGE_KEY, $LOCKING_KEY, $STORE_KEY;
78 $queue = msg_get_queue($MESSAGE_KEY);
79 msg_send($queue, 1, $msg);
83 private $semres, $msgres;