Re: Checking Server Status with PHP

From: Andrew _at_ Rockface (_at_)
Date: 01/29/05


Date: Sat, 29 Jan 2005 17:02:04 +0000 (UTC)

J.O. Aho wrote:
> Andrew @ Rockface wrote:
>> Sypher wrote:
>>
>>> Is there a simple way to check some server's status with php ?
>>> I mean, checking if some servers are up or down ...
>>> Like teamspeak server, ftp, sftp, and others, all in the local
>>> server.
>>>
>>> Thanks in advance to any who answers ...
>>> Regards
>>
>>
>> $server = "apache";
>> $up = `ps ax | grep "$server" | grep -v "grep"`;
>> if ($up != "") {echo "$server is up:<pre>$up</pre>";}
>> else {echo "$server is down:<pre>$up</pre>";}
>>
>
> Drawback: The real service may be have teken down and a service run
> as another user may be up.

Good point.

> The init script had been a better way to comfirm if the real service
> is up, but that requiers that the php script would be run as root.
>
> $server = "apache";
> $user="apache";
> $up = `ps -u $user | grep "$server" | grep -v "grep"`;
> if($up != "") {
> echo "$server is up:<pre>$up</pre>";
> } else {
> /* No point in outputting "<pre>$up</pre>" as it
> will just generate "<pre></pre>" */
> echo "$server is down!";

The flaws of cut and paste ;)

> }
>
> You should make a check for services that shouldn't be up too.
>
>
> //Aho



Relevant Pages

  • Re: grabbing an image url
    ... > cache the rss feed so I don't hit the remote server too much. ... Andrew @ Rockface np: ...
    (alt.php)
  • Re: Search help
    ... "Andrew @ Rockface" ... As Mike wrote, "If you post an example of a file ... : np: (Winamp is not active;-) ...
    (alt.php)
  • Re: Grab the properties of a mySQL table
    ... Andrew @ Rockface wrote: ... >> I'd like to write a script that allows me to modify any existing ... >> loop through each column and grab it's size and it's type. ...
    (alt.php)
  • Re: listbox problem
    ... echo buildListbox; ... Andrew @ Rockface ... np: (Winamp is not active;-) ...
    (alt.php)
  • Re: Newbie wanting to learn simple php...
    ... > Andrew @ Rockface wrote: ... >> I do use vi if I have to ssh to a remote server (several times a ...
    (alt.php)