PHP Remote Machine Checking

Fatlog
Fatlog used Ask the Experts™
on
i want to use PHP sitting on one server to check and see if another server is active(up).

this is for error checking to make sure that the other server is active before anything is sent to it.

Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
is the other machine a web server?
if so, why not just try to open an html file on the other server.

$fp = fopen ("http://www.example.com/", "r");

Commented:
I'd stick a little script on the remote server like this...

test.php
-----------
<?php

print("<server-test>"."OK"."</server-test>");

?>

On the local server, I'd stick a script like this

remote-test.php
--------------------
<?php

$s=@file("http://www.remoteserver.com/test.php");
if($s && is_array($s)){
  $s=join("",$s);
  if(preg_match("#<server-test>OK</server-test>#",$s)){
      die("Remote server's OK");
      // ... or do other stuff...
  }
}

die("Remote server's DOWN");

?>
Fatlog -
  are you just trying to test a http link or are you trying to communicate on multiple ports
CompTIA Security+

Learn the essential functions of CompTIA Security+, which establishes the core knowledge required of any cybersecurity role and leads professionals into intermediate-level cybersecurity jobs.

Author

Commented:
basically i want to make sure the http serverv on the machine is active.

i'm looking for the best way of doing this.
http://www.hotscripts.com/Detailed/17763.html

That is EXACTLY what you want, it will display an image saying whether it is active or not, but you can easily change the code...

Commented:
If you only want to see that HTTP is active (and you don't care about PHP) then you can just request a file like 'index.html' or 'test.html' and see that it is served up as expected. You can use an HTTP 'HEAD' request to save traffic, this will just return HTTP 200 OK, which means that the server is running and going fine, without sending any document traffic. That script looks promising enough too, good find from Laptop765...
Thanks, I was looking for the same thing myself, and I found it.  If you need help editing the code, let me know...

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial