It can be a little tricky if you need to restart Apache from a PHP script, this is because restarting Apache will kill the running PHP script, so the user will receive no output (or sometimes a “file download” dialog) when apache is restarted.
People may try doing something like this:
instead you need to run something in the “background” like this:
that way execution goes straight back to the php script, and our custom apache restart script waits a few seconds before restarting apache.
Another way to do this is call reload, instead of restart.