mirror of
https://github.com/RaspbianFrance/raspisms.git
synced 2025-06-06 14:46:27 +02:00
First almost working version of daemons
This commit is contained in:
parent
e709ed91b7
commit
6614c2cfeb
9 changed files with 491 additions and 20 deletions
68
daemons/Phone.php
Normal file
68
daemons/Phone.php
Normal file
|
@ -0,0 +1,68 @@
|
|||
<?php
|
||||
namespace daemons;
|
||||
|
||||
use \Monolog\Logger;
|
||||
use \Monolog\Handler\StreamHandler;
|
||||
|
||||
/**
|
||||
* Phone daemon class
|
||||
*/
|
||||
class Phone extends AbstractDaemon
|
||||
{
|
||||
private $msg_queue;
|
||||
|
||||
public function __construct($phone)
|
||||
{
|
||||
$name = 'Phone ' . $phone['number'];
|
||||
$pid_dir = PWD_PID;
|
||||
$additional_signals = [SIGUSR1, SIGUSR2];
|
||||
$uniq = true; //Main server should be uniq
|
||||
|
||||
$queue_id = (int) mb_substr($phone['number'], 1);
|
||||
$this->msg_queue = msg_get_queue($queue_id);
|
||||
|
||||
$logger = new Logger($name);
|
||||
$logger->pushHandler(new StreamHandler(PWD_LOGS . '/raspisms.log', Logger::DEBUG));
|
||||
|
||||
//Construct the server and add SIGUSR1 and SIGUSR2
|
||||
parent::__construct($name, $logger, $pid_dir, $additional_signals, $uniq);
|
||||
|
||||
//Start the daemon
|
||||
parent::start();
|
||||
}
|
||||
|
||||
|
||||
public function run()
|
||||
{
|
||||
$msgtype = null;
|
||||
$maxsize = 409600;
|
||||
$message = null;
|
||||
|
||||
msg_receive($this->msg_queue, SEND_MSG, $msgtype, $maxsize, $message);
|
||||
|
||||
if (!$message)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
$this->logger->debug(json_encode($message));
|
||||
}
|
||||
|
||||
|
||||
public function on_start()
|
||||
{
|
||||
$this->logger->info("Starting " . $this->name . " with pid " . getmypid());
|
||||
}
|
||||
|
||||
|
||||
public function on_stop()
|
||||
{
|
||||
$this->logger->info("Stopping " . $this->name . " with pid " . getmypid ());
|
||||
}
|
||||
|
||||
|
||||
public function handle_other_signals($signal)
|
||||
{
|
||||
$this->logger->info("Signal not handled by " . $this->name . " Daemon : " . $signal);
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue