mirror of
https://github.com/unraid/webgui.git
synced 2026-01-06 09:39:58 -06:00
Publish messages only when active subscribers are present
This commit is contained in:
@@ -10,20 +10,16 @@
|
||||
*/
|
||||
?>
|
||||
<?
|
||||
function curl_socket($socket, $url, $message) {
|
||||
$com = curl_init($url);
|
||||
curl_setopt_array($com,[
|
||||
CURLOPT_UNIX_SOCKET_PATH => $socket,
|
||||
CURLOPT_POST=> 1,
|
||||
CURLOPT_POSTFIELDS => $message,
|
||||
CURLOPT_RETURNTRANSFER => true
|
||||
]);
|
||||
$reply = curl_exec($com);
|
||||
curl_close($com);
|
||||
return $reply;
|
||||
}
|
||||
|
||||
function publish($endpoint, $message, $len=1) {
|
||||
return curl_socket("/var/run/nginx.socket", "http://localhost/pub/$endpoint?buffer_length=$len", $message);
|
||||
$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);
|
||||
// only send message when active subscribers are present
|
||||
if (!empty($subs[1]) && $subs[1]>0) {
|
||||
curl_setopt_array($com, [CURLOPT_POST => 1, CURLOPT_POSTFIELDS => $message]);
|
||||
$reply = curl_exec($com);
|
||||
}
|
||||
curl_close($com);
|
||||
return $reply ?? '';
|
||||
}
|
||||
?>
|
||||
|
||||
Reference in New Issue
Block a user