Codice: Seleziona tutto
<?php
if (isset($_SERVER['REMOTE_ADDR'])) {
die('Direct access not permitted');
}
// Beware, only use a tmpfs as /dev/shm (ramfs) !
while (true) {
$output = exec('/usr/bin/monitor');
usleep(2000000);
}
?>
Poi il loop lo metti dentro:
cat com_daemon.php
Codice: Seleziona tutto
<?php
/*
Start and stop in metern/config/config_daemon.php
php /srv/http/comapps/com_daemon.php { start | stop }
Request values with houseenergy command
*/
if (isset($_SERVER['REMOTE_ADDR'])) {
die('Direct access not permitted');
}
if (file_exists('/dev/shm/com_daemon.pid')) {
$cpid = (int) file_get_contents('/dev/shm/com_daemon.pid');
} else {
$cpid = null;
}
if (isset($argv[1])) {
if (($argv[1] == 'start' || $argv[1] == 'stop') && file_exists('/dev/shm/metern_log.txt')) {
unlink('/dev/shm/metern_log.txt');
}
if ($argv[1] == 'start') {
if (is_null($cpid)) {
$command = 'php /var/www/html/comapps/com_daemon_loop.php' . ' > /dev/null 2>&1 & echo $!;';
Codice: Seleziona tutto
$cpid = exec($command);
file_put_contents('/dev/shm/com_daemon.pid', $cpid);
} else {
echo "com_daemon seem to be running as $cpid";
}
} else if ($argv[1] == 'stop') {
if (!is_null($cpid)) {
$command = exec("kill -9 $cpid > /dev/null 2>&1 &");
}
unlink('/dev/shm/com_daemon.pid');
} else {
echo "Usage : com_daemon {start | stop}\n";
}
} else {
echo "Usage : com_daemon {start | stop}\n";
}
?>