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.
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:
httpd -k install
httpd -k stop httpd -k start
You can learn more commands, check the link
Example for testing
clean.bat // or what ever calling cleaning command. pause // just to test pause httpd -k stop // stops Apache
- 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.
- You can either use Xampp Gui or Xampp services, not both.
- I have test it on my machine and it works.
- It is possible to give the service a unique customized name so you can see it in Windows Services.