turn off apache

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
ratamaster
Forum Newbie
Posts: 23
Joined: Fri Oct 15, 2004 6:36 am

turn off apache

Post by ratamaster »

HI
Is there a way to turn off apache with php?
User avatar
JAB Creations
DevNet Resident
Posts: 2341
Joined: Thu Jan 13, 2005 6:44 pm
Location: Sarasota Florida
Contact:

Re: turn off apache

Post by JAB Creations »

Maybe try something like this? :mrgreen:

Code: Select all

<?php
 while(1) {
 echo "weeeeeeeeeeeeeeeeee!\n";
 }
?>
...though seriously I'm not sure. :|
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Re: turn off apache

Post 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.
ratamaster
Forum Newbie
Posts: 23
Joined: Fri Oct 15, 2004 6:36 am

Re: turn off apache

Post 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?
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Re: turn off apache

Post 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.
ratamaster
Forum Newbie
Posts: 23
Joined: Fri Oct 15, 2004 6:36 am

Re: turn off apache

Post 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()?
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Re: turn off apache

Post 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?
ratamaster
Forum Newbie
Posts: 23
Joined: Fri Oct 15, 2004 6:36 am

Re: turn off apache

Post 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');
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Re: turn off apache

Post by RobertGonzalez »

Yes, something like that (graceful is probably the best approach).

Now go try it and see if it works.
Post Reply