Nil Posted May 23, 2007 Share Posted May 23, 2007 Hi, I am new to PHP. Can anyone has idea about how to write code to ping the web/application server from PHP?. If server is down then we should able to send an email. I want this utility for web sites tracking. Please help me suggest me any code. Thanks, Nil. Quote Link to comment https://forums.phpfreaks.com/topic/52624-solved-ping-server-from-php/ Share on other sites More sharing options...
MasterACE14 Posted May 23, 2007 Share Posted May 23, 2007 Take a look at the Pinging Scripts here http://www.hotscripts.com/PHP/Scripts_and_Programs/Networking_Tools/Ping/index.html Regards ACE Quote Link to comment https://forums.phpfreaks.com/topic/52624-solved-ping-server-from-php/#findComment-259653 Share on other sites More sharing options...
Daniel0 Posted May 23, 2007 Share Posted May 23, 2007 exec('ping google.com'); Quote Link to comment https://forums.phpfreaks.com/topic/52624-solved-ping-server-from-php/#findComment-259656 Share on other sites More sharing options...
jitesh Posted May 23, 2007 Share Posted May 23, 2007 <?php $output = shell_exec('ping www.google.com'); echo "<pre>"; echo $output; ?> Quote Link to comment https://forums.phpfreaks.com/topic/52624-solved-ping-server-from-php/#findComment-259661 Share on other sites More sharing options...
MasterACE14 Posted May 23, 2007 Share Posted May 23, 2007 you could also try. <?php $_ip = $_SERVER['REMOTE_ADDR']; echo "<b>Enter the IP or the domain name of the server that you are trying to ping.</b><br>"; echo "<form method='post' action='ping.php?do=ping'><input type='text' name='domain' class='input_login' value='$_ip'> <input type='submit' value='Ping' class='input_login'></form>"; if($_GET['do'] == 'ping') { $_domain = $_POST['domain']; echo "<pre>"; system ("ping -w 10 -c 5 $_domain"); echo "</pre>"; } echo "<br>"; ?> Regards ACE Quote Link to comment https://forums.phpfreaks.com/topic/52624-solved-ping-server-from-php/#findComment-259662 Share on other sites More sharing options...
Nil Posted May 23, 2007 Author Share Posted May 23, 2007 <?php $output = shell_exec('ping www.google.com'); echo "<pre>"; echo $output; ?> Thanks jitesh But its not working is it problem with shell_exec()...? Nil Quote Link to comment https://forums.phpfreaks.com/topic/52624-solved-ping-server-from-php/#findComment-259727 Share on other sites More sharing options...
jitesh Posted May 23, 2007 Share Posted May 23, 2007 <?php echo "<pre>"; $output = system('ping www.google.com'); echo $output; ?> Quote Link to comment https://forums.phpfreaks.com/topic/52624-solved-ping-server-from-php/#findComment-259731 Share on other sites More sharing options...
Nil Posted May 23, 2007 Author Share Posted May 23, 2007 <?php $output = shell_exec('ping www.google.com'); echo "<pre>"; echo $output; ?> I am running my code win xp Quote Link to comment https://forums.phpfreaks.com/topic/52624-solved-ping-server-from-php/#findComment-259733 Share on other sites More sharing options...
jitesh Posted May 23, 2007 Share Posted May 23, 2007 I have also win xp and its working ok here. its giving me o/p as a string shown in img. [attachment deleted by admin] Quote Link to comment https://forums.phpfreaks.com/topic/52624-solved-ping-server-from-php/#findComment-259734 Share on other sites More sharing options...
Daniel0 Posted May 23, 2007 Share Posted May 23, 2007 Notice that the ping command will run until it is stopped unless otherwise specified using -c count Quote Link to comment https://forums.phpfreaks.com/topic/52624-solved-ping-server-from-php/#findComment-259768 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.