mirror of
https://github.com/fusionpbx/fusionpbx.git
synced 2025-12-30 00:53:50 +00:00
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.
This commit is contained in:
@@ -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 = "<error_msg>Invalid Profile!</error_msg>";
|
||||
$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 "<b><a href='javascript:void(0);' onclick=\"$('#status').slideToggle();\">".$text['title-status']."</a></b>\n";
|
||||
echo "<div id='status' style='margin-top: 20px; font-size: 9pt;'>";
|
||||
echo "<div class='card'>\n";
|
||||
@@ -356,5 +356,3 @@
|
||||
|
||||
//include the footer
|
||||
require_once "resources/footer.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);
|
||||
|
||||
Reference in New Issue
Block a user