Jump to content

decreasing scan time


salvador2001

Recommended Posts

Hello,

I have this script and its working fine, but there is one thing i would like to change.
When the server wich i am scanning is not online (shutted down completely) it takes 30 seconds until it shows the offline status.
I would like to decrease this to 2 to 5 seconds and let the script the server is down.

Can anyone tell me what i have to do, please a bit specific because i have poor knowledgde.

[code]<?php

set_time_limit(0); 
 
$s_port  = 12203;              // Serverport 
$s_ip    = "82.217.212.106";  // Server-IP 
$timeout = 2;
 
// CONN WRITE READ [1]
$s_con  = fsockopen("udp://".$s_ip, $s_port,$errno, $errstr, $timeout); 

// $s_con == false if fsockopen failed 
if(!$s_con)     
die(msg_server('Unable to connect with fsockopen [1];; '.$errstr)); 

// fwrite return false on write error, else it return how many bytes written 
if(fwrite($s_con, "ÿÿÿÿ". chr (0x02). "getstatus". chr (0x00))===FALSE)
die(msg_server('Unable to write to $_con [1]')); 

// fread return false on read error, else it return the read string 
if(($ffb = fread($s_con,4))===FALSE)     
    die(msg_server('Unable to read from $_con after write. [1]')); 

// stream_get_meta_data is same as socket_get_status 
$meta_data = stream_get_meta_data($s_con); 

if($meta_data["unread_bytes"]==0)
die(msg_server('server DOWN')); 

$beginnen = fread($s_con, $meta_data['unread_bytes']); 

fclose($s_con); 

$data = explode("\n", $beginnen); 

// Serverinfo 

// CONN WRITE READ [2] 
$s_con = fsockopen("udp://".$s_ip, $s_port,$errno, $errstr, $timeout); 

if(!$s_con)
die(msg_server('Unable to connect with fsockopen [2];; '.$errstr)); 

if(fwrite($s_con, "ÿÿÿÿ". chr (0x02). "getstatus". chr (0x00))===FALSE)
die(msg_server('Unable to write to $_con [2]')); 

// bytes lezen en verbindingsopbouw 
if(($ffb = fread($s_con,4))===FALSE)
die(msg_server('Unable to read from $_con after write. [2]')); 

$meta_data = stream_get_meta_data($s_con); 

if($meta_data["unread_bytes"] == 0)     
die(msg_server('No data, sorry. ('.$ffb.')')); 

$beginnen = fread($s_con, $meta_data['unread_bytes']); 

fclose($s_con); 

msg_server('server ACTIVE');   

function msg_server($server_status,$errmsg=''){     
echo "
<div class='scanner' id='hoofd'>
  <div class='picture'><img src='sc-moh.gif' alt='1' /></div>
  <div class='status'>$server_status</div>
</div>";
   
}

?>[/code]
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.