The simplest way to find out if the remote host is alive or not is to use the ping utility. Pear provides such a convenient tool.
First, you need to install the right module
Code:
Here is the php
PHP:
|
|
| require ("Net/Ping.php"); |
| |
|
|
| $ping = Net_Ping::factory(); |
| |
|
|
| if(!PEAR::isError($ping)) |
| { |
| $response = $ping->ping('REMOTE_HOST_IP_or_name'); |
| |
| if( $response->_transmitted > 0 && $response->_received ==0 && $response->_loss ==100) |
| { |
| mail("your email address", "remote host is not responding", date("Y-M-D H:i:s"), "From: your_email"); |
| }else{ |
| |
| } |
| |
| } |
The above code will send out email to you if the remote host is not responding. However, if the remote host is behind a firewall or if ping packets are blocked by firewall, the ping is not going to work.