mirror of
https://github.com/slawkens/myaac.git
synced 2025-05-24 06:24:30 +02:00
OTS_ServerInfo -> set timeout out of class
Possibility to use the class without MyAAC
This commit is contained in:
parent
43153b2b0c
commit
40d65a6613
@ -415,9 +415,11 @@ class POT
|
||||
* @tutorial POT/Server_status.pkg
|
||||
* @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->setTimeout($timeout);
|
||||
|
||||
return $status->status();
|
||||
}
|
||||
|
||||
|
@ -26,14 +26,19 @@ class OTS_ServerInfo
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $server;
|
||||
private string $server;
|
||||
|
||||
/**
|
||||
* Connection port.
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
private $port;
|
||||
private int $port;
|
||||
|
||||
/**
|
||||
* Status timeout
|
||||
*/
|
||||
private float $timeout = 2.0;
|
||||
|
||||
/**
|
||||
* Creates handler for new server.
|
||||
@ -57,7 +62,7 @@ class OTS_ServerInfo
|
||||
private function send(OTS_Buffer $packet)
|
||||
{
|
||||
// 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($socket)
|
||||
@ -224,6 +229,10 @@ class OTS_ServerInfo
|
||||
throw new OutOfBoundsException();
|
||||
}
|
||||
}
|
||||
|
||||
public function setTimeout($timeout) {
|
||||
$this->timeout = $timeout;
|
||||
}
|
||||
}
|
||||
|
||||
/**#@-*/
|
||||
|
@ -114,6 +114,8 @@ function updateStatus() {
|
||||
|
||||
// get server status and save it to database
|
||||
$serverInfo = new OTS_ServerInfo($status_ip, $status_port);
|
||||
$serverInfo->setTimeout(setting('core.status_timeout'));
|
||||
|
||||
$serverStatus = $serverInfo->status();
|
||||
if(!$serverStatus)
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user