From 2951bff6c5895590a2b8a79bddbbea62df46205f Mon Sep 17 00:00:00 2001 From: frytimo Date: Mon, 24 Nov 2025 08:30:28 -0400 Subject: [PATCH] Reuse socket connection to event socket. (#7634) Reuse the socket connection instead of creating a new connection for each API request. Add PHPDoc tag "static" for the static methods in event_socket. --- app/sip_status/sip_status.php | 14 ++++++-------- resources/classes/event_socket.php | 4 ++++ 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/app/sip_status/sip_status.php b/app/sip_status/sip_status.php index 1d119270b5..18723b3dbd 100644 --- a/app/sip_status/sip_status.php +++ b/app/sip_status/sip_status.php @@ -74,8 +74,8 @@ //get status try { - $cmd = "sofia xmlstatus"; - $xml_response = trim(event_socket::api($cmd)); + $cmd = "api sofia xmlstatus"; + $xml_response = trim($esl->request($cmd)); if ($xml_response) { //read the xml string into an xml object $xml = new SimpleXMLElement($xml_response); @@ -117,8 +117,8 @@ message::add($message, 'negative', 5000); } try { - $cmd = "sofia xmlstatus gateway"; - $xml_response = trim(event_socket::api($cmd)); + $cmd = "api sofia xmlstatus gateway"; + $xml_response = trim($esl->request($cmd)); if ($xml_response) { $xml_gateways = new SimpleXMLElement($xml_response); } @@ -255,7 +255,7 @@ //sofia status profile if ($esl && permission_exists('system_status_sofia_status_profile')) { foreach ($sip_profiles as $sip_profile_name => $sip_profile_uuid) { - $xml_response = trim(event_socket::api("sofia xmlstatus profile $sip_profile_name")); + $xml_response = trim($esl->request("sofia xmlstatus profile $sip_profile_name")); if ($xml_response == "Invalid Profile!") { $xml_response = "Invalid Profile!"; $profile_state = 'stopped'; @@ -343,7 +343,7 @@ //status if ($esl->is_connected() && permission_exists('sip_status_switch_status')) { - $response = event_socket::api("status"); + $response = $esl->request("status"); echo "".$text['title-status']."\n"; echo "
"; echo "
\n"; @@ -356,5 +356,3 @@ //include the footer require_once "resources/footer.php"; - -?> diff --git a/resources/classes/event_socket.php b/resources/classes/event_socket.php index 077968b415..afebad52f9 100644 --- a/resources/classes/event_socket.php +++ b/resources/classes/event_socket.php @@ -78,6 +78,7 @@ class event_socket { * @param string $api_cmd * * @return string|false Response from server or false if failed + * @static */ public static function api(string $api_cmd) { return self::command('api ' . $api_cmd); @@ -89,6 +90,7 @@ class event_socket { * @param string $cmd * * @return string|false Response from server or false if failed + * @static */ public static function command(string $cmd) { return self::create()->request($cmd); @@ -188,6 +190,7 @@ class event_socket { * * @return self * @global array $conf Global configuration used in config.conf + * @static */ public static function create($host = null, $port = null, $password = null, $timeout_microseconds = 30000): self { //create the event socket object @@ -265,6 +268,7 @@ class event_socket { * @param string $cmd API command to send * * @returns string $job_id the Job ID for tracking completion status + * @static */ public static function async(string $cmd) { return self::command('bgapi ' . $cmd);