ping in php code example

Example 1: php ping time

<?php
$ip_address = '123.456.789.0'; // IP address you'd like to ping.
exec("ping -c 1 " . $ip_address . " | head -n 2 | tail -n 1 | awk '{print $7}'", $ping_time);
print $ping_time[0]; // First item in array, since exec returns an array.
?>

Example 2: php ping

exec("ping ".$ip, $output, $status);
// $ip: desired ip address
// $output: result messages from the ping
// $status: result status code from the ping
//		0: success
//		1: no response
//		2: other errors