[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

Restarting Apache from PHP

Posted on 2006-11-17
5
Medium Priority
?
392 Views
Last Modified: 2010-03-04
Hello,

I'm looking for a way to restart my Apache server from PHP.  I run Apache 2 from Windows with PHP 5.
0
Comment
Question by:jtgraphic
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 13

Accepted Solution

by:
rhickmott earned 2000 total points
ID: 17977990
You should be able to use shell_exec() or system() or similar command call to execute the command

c:\www\apache2\bin\apache -k restart

You might need to give the Apache Service extra privileged see if it works first.
0
 

Author Comment

by:jtgraphic
ID: 17981716
I'm not where I can do that right now, but I figured it would be something like that.  I just couldn't find the command ANYWHERE.  Thanks for the heads up.  I'll let you know how it goes.
0
 

Author Comment

by:jtgraphic
ID: 17996959
I actually ended up restarting the services in a .bat file and executing the .bat file from the shell_exec command.  I think you've earned the points, but as a final question: do you think there is a graceful way to error handle/execute the script when apache goes down?
0
 
LVL 13

Expert Comment

by:rhickmott
ID: 17997092
Good old batch files. I had to d something similar to remote restart a machine via the web.

Some untested ideas how any of them will work practically though.

Ideally you want the script to complete before the server shuts down. Shell Exec is a difficult one though as it will hold the server up until the batch has has executed ( Basically until the command it has run and the dos windows has been terminated )

What you need is some sort of delay maybe 3 seconds or so before the command is triggered to allow the script to complete. Maybe setting up another batch file and calling a CALL BATCH2.BAT which sleeps for a few minutes then runs the command might work. If this was me I would write maybe a VB application as normally when you run them from the command line they run in windows and then halt in the command line which will probably allow it to continue. This should to allow PHP to continue on its merry way and then execute the restart 10-15 seconds later. Thats a little more challenging though.

One thing you could try would be to look at the different switches that Apache supports when restarting.

http://httpd.apache.org/docs/2.0/stopping.html

apachectl -k graceful
The USR1 or graceful signal causes the parent process to advise the children to exit after their current request (or to exit immediately if they're not serving anything). The parent re-reads its configuration files and re-opens its log files. As each child dies off the parent replaces it with a child from the new generation of the configuration, which begins serving new requests immediately.

Running the graceful switch *may* force the server to flush the script and allow it to end before hand but without testing I couldn't be sure.
0
 

Author Comment

by:jtgraphic
ID: 17997135
Thank you very much!  I'll play around with those ideas.
0

Featured Post

Free Backup Tool for VMware and Hyper-V

Restore full virtual machine or individual guest files from 19 common file systems directly from the backup file. Schedule VM backups with PowerShell scripts. Set desired time, lean back and let the script to notify you via email upon completion.  

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you are running a LAMP infrastructure, this little code snippet is very helpful if you are serving lots of HTML, JavaScript and CSS-related information. The mod_deflate module, which is part of the Apache 2.2 application, provides the DEFLATE…
Hi, in this article I'm going to teach you how to run your own site, and how to let people in (without IP). I'll talk about and explain each step... :) By the way, everything in this Tutorial is completely free and legal. This article is for …
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…
Suggested Courses
Course of the Month12 days, 19 hours left to enroll

650 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question