0

I personally don't see how this can be done even though these are my servers. But I want to know if my servers can reach external sites--ping a generic website for example--have outgoing communication. That is, I want to use execute a PHP script on one server, connecting to another of my servers, and test if the second server can ping a website, for example. So I know how to use PHP on the server my script is executing from to ping a website with fopensocket. I just don't know how to set this up to test another server's pingability. I mean I have the credentials but the only way is to have my script on each and every server and then reach the script and execute them. That is not what I want. I want to do this from the one/external server and just feed my script the ip/port/uid/pwd of the server I want to test.

Na Na
  • 41
  • 2
  • 7
  • Possible duplicate? http://stackoverflow.com/questions/9841635/how-to-ping-a-server-with-php – Zak Mar 19 '13 at 18:07
  • build a [RESTful](http://en.wikipedia.org/wiki/Representational_state_transfer) API and secure it with [OAuth](http://en.wikipedia.org/wiki/OAuth) – bitWorking Mar 19 '13 at 18:10
  • 1
    Why bother with PHP? Just `ssh server "ping ip"` – Alex Howansky Mar 19 '13 at 18:16
  • Because my dashboard is created in PHP. And this is not a duplicate of that question. That question asks how you ping another server/port. I asked how you testing ping on another server/port to yet a third location like a website. I am on server A. I want to test server B's ability to ping a website on server C. – Na Na Mar 19 '13 at 18:45
  • OK, so just run the ping through ssh2_exec(). – Alex Howansky Mar 19 '13 at 19:25
  • Yesh ssh2_exec looks like it will do it. Thanks. – Na Na Mar 20 '13 at 00:51
  • Yes using PHP's ssh2 worked. – Na Na Mar 22 '13 at 15:41

1 Answers1

0

An easy API would look something like:

SERVER1:

// get response from server2
$response = file_get_contents('http://www.server2.com/api.php?method=ping&ip=IP&port=PORT&uid=UID&pwd=PWD');
// do json_decode() if response is json string

SERVER2 (api.php):

// respond to API call
if (isset($_GET['method']) && $_GET['method'] == 'ping') {
    // get other params and do your ping function
    echo $pingresult; // perhaps a json encoded array
    exit;
}

There is no security so you could send an API password or do it with OAuth or HMAC

bitWorking
  • 12,485
  • 1
  • 32
  • 38
  • So the only way is to put a file/script on the second, third, fourth, fifth, sixth, etc servers and call it? execute it? – Na Na Mar 19 '13 at 18:44
  • or try it with a SSH php extension/library [http://kvz.io/blog/2007/07/24/make-ssh-connections-with-php/](http://kvz.io/blog/2007/07/24/make-ssh-connections-with-php/) or [http://phpseclib.sourceforge.net/](http://phpseclib.sourceforge.net/) – bitWorking Mar 19 '13 at 18:55
  • An OAuth-wrapped REST API that requires an active PHP-enabled web service on every machine? That's kinda overkill to get a ping, don't you think? – Alex Howansky Mar 19 '13 at 19:28