New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add option to ping servers #35
Comments
Or you could add a third type. You would have Ping, Website or Service. |
+1 for this option Here is a function I found to use ping with pure php (adapted from the php website : http://www.php.net/manual/en/function.socket-create.php) : function ping($host, $timeout = 1) { I tested it on Windows 7, with Xammp / php5.3 and Debian 7 / php 5.5 |
@Abawell |
See pull #92 :) |
AFTER 3 HOURS FINALLY GET A SOLUTION TO PING SERVER WITH PORT 1 .... open StatusUpdater.class.php inside function updateService at the first line add this : if (($this->server['port'])==1) {
$timeout = 5;
/* ICMP ping packet with a pre-calculated checksum */
$package = "\x08\x00\x7d\x4b\x00\x00\x00\x00PingHost";
$socket = socket_create(AF_INET, SOCK_RAW, 1);
socket_set_option($socket, SOL_SOCKET, SO_RCVTIMEO, array('sec' => $timeout, 'usec' => 0));
socket_connect($socket, $this->server['ip'], null);
$ts = microtime(true);
socket_send($socket, $package, strLen($package), 0);
if (socket_read($socket, 255)) {
$status = true;
} else {
//check error -- echo socket_last_error() . ' '. socket_strerror(socket_last_error());
$status = false;
}
$this->rtime = (microtime(true) - $starttime);
socket_close($socket);
} else
//rest of code
{ now add a server ip with port =1 and you will be able to ping it remember for win7 you must execute as admin you have to do this : Command Prompt > (Run as administrator) you have to change also response time second to milisecond |
PR in progress #102 |
hi Archangel236 i added this code in statusupdater.class.php and ping work
for me like a charm !
only one thing dont forget to change "octets=32" to your own language
machine cause for me is in french good luck
protected function updateService($max_runs, $run = 1) {
//add ping here
if (($this->server['port'])==1) {
$timeout = 5;
$ip = $this->server['ip'] ;
$ping = exec("ping -n 1 $ip",$input,$result);
$res = explode(" " , $input[2]) ;
if ($res[3] == "octets=32") {
$status = true ;
$this->rtime = (microtime(true) - $ts);
return $status;
} else
$status = false ;
if(!$status && $run < $max_runs) {
return $this->updateService($max_runs, $run + 1);
}
} else
{
$errno = 0;
// save response time
$starttime = microtime(true);
$fp = fsockopen ($this->server['ip'], $this->server['port'],
$errno, $this->error, 10);
$status = ($fp === false) ? false : true;
$this->rtime = (microtime(true) - $starttime);
if(is_resource($fp)) {
fclose($fp);
}
// check if server is available and rerun if asked.
if(!$status && $run < $max_runs) {
return $this->updateService($max_runs, $run + 1);
}
}
// end function update service
}
2015-07-03 10:37 GMT+02:00 Archangel236 <notifications@github.com>:
… ping dose not worked. If can used this code explode white page
—
Reply to this email directly or view it on GitHub
<#35 (comment)>
.
|
The current service functionality is only able to check whether a service is listening on a certain port. If you just want to ping a server without a specific port and check for response yes/no, this is not possible. A situation where a ping could be useful is for checking dyndns hostnames.
Because it is a different protocol it can not be checked with the current fsockopen(). The suggestion is to use port no. 1 for pings. So if a service is added with port=1, no fsockopen() will be used but instead an exec() to execute the ping program.
The text was updated successfully, but these errors were encountered: