This code will let you ping any ip-address or website url and get the response.
<pre>
<?php
system(‘ping -c 1 google.com’); // Ping IP address.
echo “pinged”;
?>
</pre>
The <pre> tag is used so that the code shown looks nice. 1 in the ping code indicates the number of times to ping the ipaddress or domain name url
You can either use domain name directly or the ip address that you want to ping in this code.
If you want to see if the domain can be pinged and then use the response for further process use it as follows:
<?php
if(system(‘ping -c 1 google.com’)) {
//do some thing here
}
?>
Please note, if you want to use this code to check if the domain name exists or not, then it is not a good approach, because many websites and servers have pinged response turned off (like hotmail.com and msn.com)