Added default timeout

Fixes #794.
This commit is contained in:
TimZ99 2019-10-09 22:03:53 +02:00
parent cf2566d1d3
commit 0198d76a75
No known key found for this signature in database
GPG Key ID: 4D8268DC68E8339D
4 changed files with 5 additions and 4 deletions

View File

@ -354,7 +354,7 @@ function psm_parse_msg($status, $type, $vars, $combi = false) {
* @return string cURL result
*/
function psm_curl_get($href, $header = false, $body = true, $timeout = null, $add_agent = true, $website_username = false, $website_password = false, $request_method = null, $post_field = null) {
$timeout = $timeout == null ? PSM_CURL_TIMEOUT : intval($timeout);
($timeout === null || $timeout > 0) ? PSM_CURL_TIMEOUT : intval($timeout);
$ch = curl_init();
if(defined('PSM_DEBUG') && PSM_DEBUG === true && psm_is_cli()) {

View File

@ -252,7 +252,7 @@ class ServerController extends AbstractServerController {
$clean = array(
'label' => trim(strip_tags(psm_POST('label', ''))),
'ip' => trim(strip_tags(psm_POST('ip', ''))),
'timeout' => (isset($_POST['timeout']) && intval($_POST['timeout']) > 0) ? intval($_POST['timeout']) : null,
'timeout' => (isset($_POST['timeout']) && intval($_POST['timeout']) > 0) ? intval($_POST['timeout']) : 10,
'website_username' => psm_POST('website_username'),
'website_password' => $encrypted_password,
'port' => intval(psm_POST('port', 0)),

View File

@ -202,11 +202,12 @@ class StatusUpdater {
* @return boolean
*/
protected function updateService($max_runs, $run = 1) {
$timeout = ($this->server['timeout'] === null || $this->server['timeout'] > 0) ? PSM_CURL_TIMEOUT : intval($this->server['timeout']);
$errno = 0;
// save response time
$starttime = microtime(true);
$fp = @fsockopen($this->server['ip'], $this->server['port'], $errno, $this->error, $this->server['timeout']);
$fp = @fsockopen($this->server['ip'], $this->server['port'], $errno, $this->error, $timeout);
$status = ($fp === false) ? false : true;
$this->rtime = (microtime(true) - $starttime);

View File

@ -115,7 +115,7 @@
<!-- Warning threshold -->
{{ macro.input_field("number", "warning_threshold", null, "warning_threshold", label_warning_threshold, edit_value_warning_threshold, "0", "5", 'warning_threshold_help', label_warning_threshold_description) }}
<!-- Timeout -->
{{ macro.input_field("number", "timeout", null, "timeout", label_timeout, edit_value_timeout, null, "10", 'timeout_help', label_timeout_description) }}
{{ macro.input_field("number", "timeout", null, "timeout", label_timeout, edit_value_timeout, default_value_timeout, "10", 'timeout_help', label_timeout_description) }}
</div>
</fieldset>
<fieldset class="types typeWebsite">