• Howdy! Welcome to our community of more than 130.000 members devoted to web hosting. This is a great place to get special offers from web hosts and post your own requests or ads. To start posting sign up here. Cheers! /Peo, FreeWebSpace.net
managed wordpress hosting

need help with a script im writing.

GregT

Waffles!!
NLC
Im starting on writing an Admin Control Panel for pl-serv on linux, and was wondering how do i make php check to see if the httpd and mysqld are runnin ? so far i got

PHP:
<?php
if(//Check if httpd is running goes here)
echo "Apache is running";
else {
echo "Apache is not running";

if(//Check if mysqld is running code goes here)
echo "MySQL is running";
else {
echo "MySQL is not running";
?>

all i need is the part that checks if Apache and MySQL are running how would i do this ?

<<edit>> i think i figured out the mysql chk but not apache

PHP:
<?php
if(Check if httpd is running)
echo "Apache is running";
else {
echo "Apache is not running";

if($link = mysql_connect (localhost, admin, scripts))
echo "MySQL is running";
else {
echo "MySQL is not running"
?>
 
Last edited:
wtf is wrong wit my code i get
Parse error: parse error in /home/virtual/site45/fst/home/gt/public_html/scripts/mysqlchk.php on line 8

line 8 is ?>
 
Code:
<?php

if(//Check if httpd is running goes here) {
     echo "Apache is running";
} else {
     echo "Apache is not running";
}

if(//Check if mysqld is running code goes here) {
     echo "MySQL is running";
} else {
     echo "MySQL is not running";
}

?>
 
It is not in PHP. If you don't like it, don't use it.


Code:
#!/usr/bin/perl
use strict;

my $apache_pid_file = q(/var/run/httpd.pid);

##### If you are showing this on the web, uncomment the line below #####
# print "Content-Type: text/html\n\n";

my($status,$date) = split(/\t/,check_status());

if($status) {
        print "Apache is running since ". $date;
} else {
        print "Apache is not running";
}


sub check_status {
        if(open(PID, $apache_pid_file) && <PID> =~ /(\d+)/ && kill(0, $1)) {
                close(PID);
                my @st = stat($apache_pid_file);
                return join("\t",(1,scalar(localtime($st[9]))));
        } else {
                return 0;
        }
}
 
__END__

< EDIT > I edited the code above so it only goes to the subroutine check_status once. So it should runs faster now. :classic2:
 
Last edited:
i always get them damn { } thingys messed up thnx yupapa, is there a way to turn off mysql error reporting ?

thnx yupapa, im writing a php panel, but if i cant get anything else i'll use this.
 
ok i found out how to do it apache a bit,

how do i make php check to see if httpd.pid exsist ?
PHP:
<?php
if(/var/run/httpd.pid exists) {
     echo "Apache is running";
} else {
      echo "Apache is not running";

}
?>

sumthing like that ?
 
like this:
PHP:
<?php
if(file_exists("/var/run/httpd.pid")) {
     echo "Apache is running";
} else {
      echo "Apache is not running";

}
?>
 
Well, if(file_exists("/var/run/httpd.pid")) should work...

And, to turn off mysql error reporting, call the functions like :


@mysql_connect(...)

Rapmaster beat me...
 
Originally posted by rapmaster
like this:
PHP:
<?php
if(file_exists("/var/run/httpd.pid")) {
     echo "Apache is running";
} else {
      echo "Apache is not running";

}
?>

i knew i was close, :) thnx guys
 
tsk tsk tsk..

You all think to hard :) . Look at this
PHP:
<?php
$apache = getallheaders() or
die("Apache Is Not Running or PHP Is Not Installed As A Mod.");
$mysql = mysql_connect("localhost", "mysql_user", "mysql_password") or
die("There Is No MySQL or You Have Login Details Incorrect");
echo "Connected to MySQL";
?>

Ok getallheaders() is an Apache only command and will only work when apache is on. It diplays all the HTTP headers. Then the basic MySQL connection. If you want to know what your host is using just do a phpinfo() and it will tell u everything you need to know about that host. Example:
http://members.lycos.co.uk/phpman/phpinfo.php
 
umm, PHPMan thats not what i need though, plus wont work with my setup, this script will be running on a seperate apache server, if it was on the same why the hell would i want to see if apache is up? i would be able tell by not being able to access the page :D The setup i have is perfect, i going to add stop and start buttons and put it on the main page of my server panel :)
 
.....

Originally posted by gt14
umm, PHPMan thats not what i need though, plus wont work with my setup, this script will be running on a seperate apache server, if it was on the same why the hell would i want to see if apache is up? i would be able tell by not being able to access the page :D The setup i have is perfect, i going to add stop and start buttons and put it on the main page of my server panel :)
......You don't run the script on your server.. You upload it to the server your gona run things from.
 
Re: .....

Originally posted by PHPMan

......You don't run the script on your server.. You upload it to the server your gona run things from.

umm, no- im writing a admin panel for pl-serv (visit my site to learn what that is)
 
So you want this script to execute remotely? Huh? You can't file_exists remote files. What you could do is fopen a remote file on the server, but it would have to be available for remote access.
 
Originally posted by Canuckkev
So you want this script to execute remotely? Huh? You can't file_exists remote files. What you could do is fopen a remote file on the server, but it would have to be available for remote access.

does nobody understand what im saying !!!! pl-serv is a Apache/MySQL/PHP/Perl installer and configurer ! The admin panel runs on a seperate Apache Server installed on 1 server as in http://localhost : normal server http://localhost:8001 Admin Panel , Two Apaches 1 server, get it now !?!?
 
Originally posted by rapmaster
like this:
PHP:
<?php
if(file_exists("/var/run/httpd.pid")) {
     echo "Apache is running";
} else {
      echo "Apache is not running";

}
?>


You sure that works? Even if apache is not running, the proccess file is still there but it would be empty. If it is running, it should have the pid id in there.

< EDIT > and by the way, the apache pid file maybe not stored in the same place. You an find where that pid file is by typing 'locate httpd.pid' via SSH and it should tell you where on earth that pid file is.
 
Last edited:
Re: tsk tsk tsk..

Originally posted by PHPMan
PHP:
<?php
$apache = getallheaders() or
die("Apache Is Not Running or PHP Is Not Installed As A Mod.");
$mysql = mysql_connect("localhost", "mysql_user", "mysql_password") or
die("There Is No MySQL or You Have Login Details Incorrect");
echo "Connected to MySQL";
?>

BUT that only check if the script could connect to the database. It doesn't have anything to check if mySQL is running though.
 
Originally posted by YUPAPA



You sure that works? Even if apache is not running, the proccess file is still there but it would be empty. If it is running, it should have the pid id in there.

< EDIT > and by the way, the apache pid file maybe not stored in the same place. You an find where that pid file is by typing 'locate httpd.pid' via SSH and it should tell you where on earth that pid file is.

im doing the first version on windows then porting to linux so where its located is no prob. later i will right sumthing in shell script to fix that and apache 1.3.26 deletes the pid file when it shutsdown, so yes it works.
 
Back
Top