Skip to content

Instantly share code, notes, and snippets.

@ryjkov
Created December 26, 2011 12:17
Show Gist options
  • Save ryjkov/1521052 to your computer and use it in GitHub Desktop.
Save ryjkov/1521052 to your computer and use it in GitHub Desktop.
PHP - Ping
<?php
if (substr(PHP_OS, 0, 3) == 'WIN') {
$ping = 'ping -n 5 ';
} else {
$ping = 'ping -c 5 ';
}
$ping .= 'yandex.ru';
$ph = popen($ping, 'r') or die('popen() failed');
$output = '';
while ($buf = fgets($ph, 1024)) {
$output .= $buf;
}
$ec = pclose($ph);
echo 'cmd: ' . $ping . '<br />';
echo 'exit code: ' . $ec . '<br />';
echo 'output:' . '<br />';
echo nl2br($output);
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment