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 independent from XAMPP in case of re-installation or changing environment.
The step to reach the goal:
- Run
cmd
as administrator
- Go to your XAMPP Apache bin folder
- Install Apache as service,
httpd -k install
- 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
- 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
Notes:
- 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.