Reply to Re: [PHP] exec ping

Your name:

Reply:


Posted by Juan Pablo Herrera on 08/21/05 09:34

On 8/21/05, Jasper Bryant-Greene <jasper@bryant-greene.name> wrote:
> Juan Pablo Herrera wrote:
> > Thanks Jasper,
> > well, i need make a explode of results of the ping. The idea is check
> > a host and when the host don´ t response send a email.
> > I don't explode the result of the ping.
>
> If it was me, I'd try opening a socket connection to the host instead,
> and check to see if you can connect or not. Whether or not that is
> suitable to your application I don't know...
>
> Jasper
>

Hi!
I did following script:

<?php
// Exec a ping
exec('ping -c 5 192.168.236.3',$result);
// Take result from icmp seq = 2
$icmp = strpos($result[2], 'time=');

$icmp = $icmp + 5;

$fin = strpos($result[2], 'ms');
// This is my end
$fin = $fin - $icmp;
// I take only the ms time
$text = substr($result[2],$icmp,$fin);
// Strip whitespace
$ms = trim($text);

if (!is_numeric($ms)) {
$a = 'myemail@host.com';
$asunto = "Servidor Caido";
$mensaje = "Posible caida del servidor. No responde PING.";
mail($a, $asunto, $mensaje);
}

?>

It's very simple, but i think that is working. I will add other options.

JP

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация