$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 (($reply['subscribers']??0)>0) { curl_setopt_array($com, [CURLOPT_POST => 1, CURLOPT_POSTFIELDS => $message]); $reply = json_decode(curl_exec($com),true); } curl_close($com); // return number of active subscribers return $reply['subscribers']??0; } function publish($endpoint, $message, $len=1) { return curl_socket("/var/run/nginx.socket", "http://localhost/pub/$endpoint?buffer_length=$len", $message); } ?>