guif Posted October 8, 2008 Share Posted October 8, 2008 I would like to make a simple monitoring. I make this: <?php $ip = $_SERVER['127.0.0.1']; exec("ping -n 4 $ip 2>&1", $output, $retval); if ($retval != 0) { echo "no!"; } else { echo "yes!"; } ?> I use my internal IP: 127.0.0.1. The result is: NO! why??? Quote Link to comment https://forums.phpfreaks.com/topic/127515-make-ping-with-php/ Share on other sites More sharing options...
davidkierz Posted October 8, 2008 Share Posted October 8, 2008 exec("ping -n -c 4 $ip 2>&1", $output, $retval); Quote Link to comment https://forums.phpfreaks.com/topic/127515-make-ping-with-php/#findComment-659747 Share on other sites More sharing options...
guif Posted October 8, 2008 Author Share Posted October 8, 2008 not's run. The result is: no! Quote Link to comment https://forums.phpfreaks.com/topic/127515-make-ping-with-php/#findComment-659764 Share on other sites More sharing options...
guif Posted October 8, 2008 Author Share Posted October 8, 2008 I change this code and I put this: IP: 10.140.206.123 ( <?php $ping_ex = exec("ping -n 1 10.110.206.123", $ping_result, $pr); if (count($ping_result) > 1){ echo "<img src=\"on.png\">"; } else{ echo "<img src=\"off.png\">"; } ?> ) IP: 127.0.0.1 ( <?php $ping_ex = exec("ping -n 1 127.0.0.1", $ping_result, $pr); if (count($ping_result) > 1){ echo "<img src=\"on.png\">"; } else{ echo "<img src=\"off.png\">"; } ?> ) In the first case the resulst are NO and the second case are YES. But... the result is YES in two cases. Why??? Quote Link to comment https://forums.phpfreaks.com/topic/127515-make-ping-with-php/#findComment-659871 Share on other sites More sharing options...
guif Posted October 9, 2008 Author Share Posted October 9, 2008 yeah! finally I put this code: <?php $str = exec("ping -n 1 -w 1 100.100.100.100", $input, $result); if ($result == 0){ echo "<img src=\"on.png\">"; }else{ echo "<img src=\"off.png\">"; } ?> It's run correctly, but i would like to insert this code into a javascript function because I insert many times this PHP and the page is very hard to load. I would like to insert a button: <input type="submit" onClick="para();"> and when I press this button, the javascript runs. Is it possible?? Quote Link to comment https://forums.phpfreaks.com/topic/127515-make-ping-with-php/#findComment-660771 Share on other sites More sharing options...
Dathremar Posted October 9, 2008 Share Posted October 9, 2008 Well I would use ajax for that.. Think that will be a good solution Quote Link to comment https://forums.phpfreaks.com/topic/127515-make-ping-with-php/#findComment-660772 Share on other sites More sharing options...
guif Posted October 10, 2008 Author Share Posted October 10, 2008 did you know any tutorial, blog or any page to explain my question??? Quote Link to comment https://forums.phpfreaks.com/topic/127515-make-ping-with-php/#findComment-661841 Share on other sites More sharing options...
Lamez Posted October 10, 2008 Share Posted October 10, 2008 I took this snippet out of my ELC(External Link Checker), http://links.lamezz.com Type in the IP address to ping. <?php $url = "127.0.0.1"; $churl = @fopen($url,'r'); if (!$churl && !empty($url)){ echo "<br><center>The URL does not exist, or the server is down.</center>"; }else{ echo "<br><center>The URL does exist!</center>"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/127515-make-ping-with-php/#findComment-661860 Share on other sites More sharing options...
guif Posted October 13, 2008 Author Share Posted October 13, 2008 I use this code, but if I put many times the code for my different servers the refresh of the page is very slow... Is it easy and possible accelerate my page? Quote Link to comment https://forums.phpfreaks.com/topic/127515-make-ping-with-php/#findComment-664027 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.