How to ping domain name url or ip address using PHP

This code will let you ping any ip-address or website url and get the response.



system(‘ping -c 1’); // Ping IP address.

echo “pinged”;



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:


if(system(‘ping -c 1’)) {

//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 and

Leave a Reply

Your email address will not be published.