Page 1 of 1

turn off apache

Posted: Thu Jun 05, 2008 12:37 pm
by ratamaster
HI
Is there a way to turn off apache with php?

Re: turn off apache

Posted: Thu Jun 05, 2008 2:00 pm
by JAB Creations
Maybe try something like this? :mrgreen:

Code: Select all

<?php
 while(1) {
 echo "weeeeeeeeeeeeeeeeee!\n";
 }
?>
...though seriously I'm not sure. :|

Re: turn off apache

Posted: Fri Jun 06, 2008 12:57 am
by RobertGonzalez
Can I ask why you would want to do that?

For the record, you can. You would need to somehow su to root then call a shell command to do it. It is a lot easier to do this at the command line since doing it by way of the web server means losing PHP as soon as Apache stops.

Re: turn off apache

Posted: Fri Jun 06, 2008 9:14 am
by ratamaster
Actually I don't want this :) the customer wants it.
This is for a intranet frontend.
We need
- Restart
- Update
- Shutdown

Could you give me an example pls?

Re: turn off apache

Posted: Fri Jun 06, 2008 10:47 am
by RobertGonzalez
Create a shell script that does all that for you. Then call the shell script. Be prepared for unexpected results with this though.

Re: turn off apache

Posted: Fri Jun 06, 2008 11:01 am
by ratamaster
Create a shell script that does all that for you. Then call the shell script. Be prepared for unexpected results with this though.

Could you write an example pls! I have no idea how achieve this, should I use the function exec()?

Re: turn off apache

Posted: Fri Jun 06, 2008 11:13 am
by RobertGonzalez
You can use exec or you can backtick your command. Do you have knowledge of how to control apache from the command line?

Re: turn off apache

Posted: Fri Jun 06, 2008 11:21 am
by ratamaster
how could it be? something like this into a php file:

<?php
exec('apachectl -k stop');
?>

or
exec('apachectl -k stop');
exec('apachectl -k graceful');

Re: turn off apache

Posted: Fri Jun 06, 2008 11:27 am
by RobertGonzalez
Yes, something like that (graceful is probably the best approach).

Now go try it and see if it works.