Link to home
Start Free TrialLog in
Avatar of tonelm54
tonelm54

asked on

PHP Ping

Good morning,
Ive been trying to get a Ping working on a server, just to test if a particular server is up and working.

Ive tried system, exec, and passthru but get the error messeage:-
Warning: EXEC functions have been disabled for security reasons.

I have managed to get the following code working on my web and mail servers:-
<?php
$fp = fsockopen ("87.105.128.62", 25, $errno, $errstr, 30);
if (!$fp) {
   echo "Failed";
} else {

   echo ('Pinged OK');
   fclose ($fp);
} 
?>

Open in new window


Is it possible to open a socket up to a server that doesnt have a web or mail server on? Prefebably a ping request, but I know Pings work differently to this my using ICMP instead of TCP or UDP.

Thank you
Avatar of Pratima
Pratima
Flag of India image

try this

<?php

$output = shell_exec('ping www.google.com');
echo "<pre>";e
cho $output;?>

refer

http://php.bigresource.com/Track/php-wc8hpzxd/
Avatar of tonelm54
tonelm54

ASKER

Sorry, trying the shell_exec, I still get:-
Warning: EXEC functions have been disabled for security reasons in /home/vincienergies/7KEXM7KR/htdocs/testPing.php on line 2
ASKER CERTIFIED SOLUTION
Avatar of NurAzije
NurAzije
Flag of Bosnia and Herzegovina image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
try this
$strPing= `ping -ns www.whatever.com 4 4`;
echo "<pre>";
echo $strPing;
echo "</pre>";

OR

<?

$host='CHANGETHISTOYOURHOST';
$strPing= `ping $host`;
$posstring = strpos($strPing, "Please", 1);
if ($posstring == 0)
{ echo "Server online!"; }
else
{ echo "Server offline!"; }

?>