Moisés Moisés - 1 year ago 118
Apache Configuration Question

Run command before exit apache/xampp

Is there a way to run a command/method when Apache is about to exit?

I have an application running in windows with Xampp (local use only), and want to make some kind of cleanup method when this application is ended by the user, which happens when Apache's stop button is pushed.

So any kind of event fired by xampp or apache, or even php that I can use?
And the command can be from cmd, php, whatever.

OBS: must be something before apache's closed, so check windows process list isn't an option.

Answer Source

IMO, I would suggest you make a batch file that do stop Apache and call your cleaning command before or after stopping command.

This way the batch file is in depended from XAMPP in case of re-installation or changing environment.

The step to reach the goal:

  1. Run cmd as administrator
  2. Go to your Xampp Apache bin folder
  3. Install apache as service, httpd -k install
  4. Now you should be able to manually start and stop Apache by command line
httpd -k stop
httpd -k start

You can learn more commands, check the link

  1. Now make a batch file call it any thing you like, that do cleaning job and put it before or after you stop or start Apache

Example for testing cleanandstopapache.bat:

clean.bat // or what ever calling cleaning command.
pause // just to test pause
httpd -k stop // stops Apache


  1. Normally you start and stop your Xampp via GUI. Using service has the same effect the only different is, that you gone use command line to start and stop your Apache, that said you can put any script before stop Apache to do the job.
  2. You can either use Xampp Gui or Xampp services, not both.
  3. I have test it on my machine and it works.
  4. It is possible to give the service a unique customized name so you can see it in Windows Services.
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download