11

As the title says, I want to know if it is be possible to automatically launch a PHP script when a restart of apache is done.

MORE INFO EDIT:

I will try to explain what is the purpose of this, the best I can. We are currently refactoring our application and we'll be stuck with 2 differents configuration file system for the time being, until all of the application flows are refactored (might take more than a year). The old one is using simple flat file in the key=value format (i.e. www.conf), while the new system will use cacheable php files (i.e. www.php). We need to replicate to www.php any config changes made in www.conf.

Since Apache gets restarted whenever there is a config change in www.conf, I thought it might be a good workaround solution to launch a PHP script, that would replicate the www.conf to www.php.

BЈовић
  • 62,405
  • 41
  • 173
  • 273
josephdotca
  • 378
  • 1
  • 4
  • 18

2 Answers2

11

You need to modify you startup script for your apache.

Open your startup script, it should be in /etc/init.d/apache or apache2

Search for the start / restart section and add your cli call for your PHP script.

Example:

    restart)
            [..]
            php -q /tmp/myscript.php &
            ;;

Where /tmp/myscript.php is your php script that you want to launch.

The "&" at the end will start the script in the background so your startup will not wait until your php script has ended. If you want to wait until it has ended, remove the &.

You should not put such thing into your startup scripts, there might be better solutions. What are trying to achieve?

favo
  • 5,426
  • 9
  • 42
  • 61
  • The binary location differs from system to system and compiling options ;) – favo Jun 07 '10 at 22:51
  • I tried to explain more precisely the goal of this in my first post. Would you know of a better solution? – josephdotca Jun 08 '10 at 12:35
  • In that situation I would take the same approach. Its the easiest way and because you already have the restart in your update workflow, you won't have to add a new step. If the restart wouldn't be part of your current process, I would setup a process that checks for file changes and converts the config file if any changes are detected, most probably in a cronjob. – favo Jun 08 '10 at 17:00
  • Actually, i want to run .php file when Apache start on xampp control Panel, is it possible? please, tell me details.. – Wahid4sap Feb 12 '13 at 17:20
2

At the risk of offending people (like myself) who prefer neat clean solutions, is changing the Apache's default start script an option for you? If so, that'd be the simplest solution

DVK
  • 126,886
  • 32
  • 213
  • 327
  • 4
    Not a real answer - these types of things should be posted as a comment, no? – barfoon Jun 07 '10 at 20:39
  • the -1 is not from me, but maybe you should put such comment into the comment section – favo Jun 07 '10 at 20:39
  • 1
    It was a real answer wrapped in a conditional, so no. – DVK Jun 07 '10 at 20:40
  • 1
    Question is is it possible - your answer doesnt answer that and questions the approach. – barfoon Jun 07 '10 at 20:42
  • 2
    I bet it's just a matter of phrasing. `Changing the Apache's default start script would be the simplest solution (if that's an option for you)` probably wouldn't have garnered a downvote. – webbiedave Jun 07 '10 at 20:44
  • 2
    @barfoon: Sometimes the approach is nonsense and it's best to propose another approach, or find out what the asker really wants to do. (Although I think webbiedave's comment on the question is better there than this answer) – Marian Jun 07 '10 at 21:04
  • Understandable, just trying to do my part as a stackoverflow citizen. – barfoon Jun 08 '10 at 13:48