mirror of
https://github.com/RaspbianFrance/raspisms.git
synced 2025-04-22 09:26:27 +02:00
Add delay between two read operation on daemon phones to prevent too many api call
This commit is contained in:
parent
3f632e9db7
commit
cc188f3118
1 changed files with 10 additions and 2 deletions
|
@ -20,6 +20,7 @@ use Monolog\Logger;
|
||||||
class Phone extends AbstractDaemon
|
class Phone extends AbstractDaemon
|
||||||
{
|
{
|
||||||
private $max_inactivity = 5 * 60;
|
private $max_inactivity = 5 * 60;
|
||||||
|
private $read_delay = 20 / 0.5;
|
||||||
private $msg_queue;
|
private $msg_queue;
|
||||||
private $msg_queue_id;
|
private $msg_queue_id;
|
||||||
private $webhook_queue;
|
private $webhook_queue;
|
||||||
|
@ -56,13 +57,20 @@ class Phone extends AbstractDaemon
|
||||||
{
|
{
|
||||||
usleep(0.5 * 1000000); //Micro sleep for perfs
|
usleep(0.5 * 1000000); //Micro sleep for perfs
|
||||||
|
|
||||||
|
$read_tick = ($read_tick ?? 0) + 1; //Count tick
|
||||||
|
|
||||||
$this->bdd = \descartes\Model::_connect(DATABASE_HOST, DATABASE_NAME, DATABASE_USER, DATABASE_PASSWORD, 'UTF8');
|
$this->bdd = \descartes\Model::_connect(DATABASE_HOST, DATABASE_NAME, DATABASE_USER, DATABASE_PASSWORD, 'UTF8');
|
||||||
|
|
||||||
//Send smss in queue
|
//Send smss in queue
|
||||||
$this->send_smss();
|
$this->send_smss();
|
||||||
|
|
||||||
//Read received smss
|
//Read only every x ticks (x/2 seconds) to prevent too many call
|
||||||
$this->read_smss();
|
if ($read_tick >= $this->read_delay)
|
||||||
|
{
|
||||||
|
//Read received smss
|
||||||
|
$this->read_smss();
|
||||||
|
$read_tick = 0;
|
||||||
|
}
|
||||||
|
|
||||||
//Stop after 5 minutes of inactivity to avoid useless daemon
|
//Stop after 5 minutes of inactivity to avoid useless daemon
|
||||||
if ((microtime(true) - $this->last_message_at) > $this->max_inactivity)
|
if ((microtime(true) - $this->last_message_at) > $this->max_inactivity)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue