Building a queue for sending notifications to the pushover API

236 Views Asked by At

I've build a little website where users are able to send notifications to other users through pushover (https://www.pushover.net).

Everything is working fine except the limitation besides pushover (https://pushover.net/api#limits):

"Do not send more than 2 concurrent HTTP requests (TCP connections) to our API..... To speed up multiple requests, you may send each request in sequence over the same TCP connection using HTTP keep-alive to avoid the overhead of a new TCP connection and SSL negotiation. Do not retry the same request more than once every 5 seconds. ....".

So as I understand I have to send less than 2 Messages in 5 Seconds right? But in my case I have round about 4-5 messages/second sometimes. has anyone an idea how to do this "HTTP keep-alive"-thing to keep it going?

For sending I actually use "php-pushover" from Chris Schalenborgh.

My method looks like this:

function alertSend($title, $message, $participants, $account){
    $timestamp = time();
    $datum = date("d.m.Y - H:i", $timestamp);
    $pushover = new Pushover();
    $pushover->setToken($account->alerts);
    $pushover->setUser($account->usertoken);
    $devices = validateUser($account->alerts, $account->usertoken, $account->verify);
    foreach($participants as $user){
        if (strpos($devices, $user) !== false) {
            $final .= $user.",";
        }
    }
    if(!empty($final)){
        $pushover->setDevice($final);
        $pushover->setPriority('1');
        $pushover->setExpire('300');
        $pushover->setRetry('30');
        $pushover->setTitle($title);
        $pushover->setMessage($message);

        if(isset($final)){
            $final = '';
        }
    }
}

In my opinion there is no failure generally.

I hope that anyone has an answer how to solve this.

0

There are 0 best solutions below