OTS_ServerInfo -> set timeout out of class

Possibility to use the class without MyAAC
This commit is contained in:
slawkens 2025-05-23 16:11:57 +02:00
parent 43153b2b0c
commit 40d65a6613
3 changed files with 17 additions and 4 deletions

View File

@ -415,9 +415,11 @@ class POT
* @tutorial POT/Server_status.pkg * @tutorial POT/Server_status.pkg
* @deprecated 0.1.4 Use OTS_ServerInfo->status(). * @deprecated 0.1.4 Use OTS_ServerInfo->status().
*/ */
public static function serverStatus($server, $port) public static function serverStatus($server, $port, $timeout = 2.0)
{ {
$status = new OTS_ServerInfo($server, $port); $status = new OTS_ServerInfo($server, $port);
$status->setTimeout($timeout);
return $status->status(); return $status->status();
} }

View File

@ -26,14 +26,19 @@ class OTS_ServerInfo
* *
* @var string * @var string
*/ */
private $server; private string $server;
/** /**
* Connection port. * Connection port.
* *
* @var int * @var int
*/ */
private $port; private int $port;
/**
* Status timeout
*/
private float $timeout = 2.0;
/** /**
* Creates handler for new server. * Creates handler for new server.
@ -57,7 +62,7 @@ class OTS_ServerInfo
private function send(OTS_Buffer $packet) private function send(OTS_Buffer $packet)
{ {
// connects to server // connects to server
$socket = @fsockopen($this->server, $this->port, $error, $message, setting('core.status_timeout')); $socket = @fsockopen($this->server, $this->port, $error, $message, $this->timeout);
// if connected then checking statistics // if connected then checking statistics
if($socket) if($socket)
@ -224,6 +229,10 @@ class OTS_ServerInfo
throw new OutOfBoundsException(); throw new OutOfBoundsException();
} }
} }
public function setTimeout($timeout) {
$this->timeout = $timeout;
}
} }
/**#@-*/ /**#@-*/

View File

@ -114,6 +114,8 @@ function updateStatus() {
// get server status and save it to database // get server status and save it to database
$serverInfo = new OTS_ServerInfo($status_ip, $status_port); $serverInfo = new OTS_ServerInfo($status_ip, $status_port);
$serverInfo->setTimeout(setting('core.status_timeout'));
$serverStatus = $serverInfo->status(); $serverStatus = $serverInfo->status();
if(!$serverStatus) if(!$serverStatus)
{ {