mirror of
https://github.com/unraid/webgui.git
synced 2026-05-04 08:49:47 -05:00
Publish messages only when active subscribers are present
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
<?PHP
|
||||
/* Copyright 2005-2023, Lime Technology
|
||||
* Copyright 2012-2023, Bergware International.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License version 2,
|
||||
@@ -12,14 +13,15 @@
|
||||
<?
|
||||
function publish($endpoint, $message, $len=1) {
|
||||
$com = curl_init("http://localhost/pub/$endpoint?buffer_length=$len");
|
||||
curl_setopt_array($com, [CURLOPT_UNIX_SOCKET_PATH => "/var/run/nginx.socket", CURLOPT_RETURNTRANSFER => true]);
|
||||
preg_match('/subscribers: (\d+)/', curl_exec($com), $subs);
|
||||
curl_setopt_array($com, [CURLOPT_UNIX_SOCKET_PATH => "/var/run/nginx.socket", CURLOPT_HTTPHEADER => ['Accept:text/json'], CURLOPT_RETURNTRANSFER => 1]);
|
||||
$reply = json_decode(curl_exec($com),true);
|
||||
// only send message when active subscribers are present
|
||||
if (!empty($subs[1]) && $subs[1]>0) {
|
||||
if (($reply['subscribers']??0)>0) {
|
||||
curl_setopt_array($com, [CURLOPT_POST => 1, CURLOPT_POSTFIELDS => $message]);
|
||||
$reply = curl_exec($com);
|
||||
$reply = json_decode(curl_exec($com),true);
|
||||
}
|
||||
curl_close($com);
|
||||
return $reply ?? '';
|
||||
// return number of active subscribers
|
||||
return $reply['subscribers']??0;
|
||||
}
|
||||
?>
|
||||
|
||||
Reference in New Issue
Block a user