PHP Network: Pinging Remote Hosts


PHP Network Tips - Part 1: If we want to check if a network host is alive, we use ping system command. Example, if we want to check phpeveryday.com is alive we can use ping phpeveryday.com (for Windows). We can use ping at PHP. The code like this:
<?php
exec("ping localhost", $output);
echo "<pre>".join("\r\n", $output)."</pre>";
?>

Ping command depend on Operating System. I use Win XP. And I just check localhost. You can try other network host by replace localhost above. Result may like this:

Pinging DIGI01 [127.0.0.1] with 32 bytes of data:

Reply from 127.0.0.1: bytes=32 time<1ms TTL=128
Reply from 127.0.0.1: bytes=32 time<1ms TTL=128
Reply from 127.0.0.1: bytes=32 time<1ms TTL=128
Reply from 127.0.0.1: bytes=32 time<1ms TTL=128

Ping statistics for 127.0.0.1:
    Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
    Minimum = 0ms, Maximum = 0ms, Average = 0ms



Bookmark and Share Tag: network, ping, remote host Category: PHP Basic Post : April 28th 2008 Read: 4,501

advertisements


blog comments powered by Disqus