Skip to content

Instantly share code, notes, and snippets.

@benedict-erwin
Last active July 2, 2019 17:00
Show Gist options
  • Save benedict-erwin/7f6ce8d0ae90dac7ad55067f52bb7761 to your computer and use it in GitHub Desktop.
Save benedict-erwin/7f6ce8d0ae90dac7ad55067f52bb7761 to your computer and use it in GitHub Desktop.

Revisions

  1. benedict-erwin revised this gist Jul 2, 2019. 1 changed file with 2 additions and 0 deletions.
    2 changes: 2 additions & 0 deletions php-as-daemon.md
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,5 @@
    # Run PHP Script as Daemon in Linux (ubuntu) with Upstart

    ## How to set it up:
    Create a config file for your phpdaemon at /etc/init/phpdaemon.conf
    ```conf
  2. benedict-erwin revised this gist Jul 2, 2019. 1 changed file with 3 additions and 3 deletions.
    6 changes: 3 additions & 3 deletions php-as-daemon.md
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,4 @@
    ##How to set it up:
    ## How to set it up:
    Create a config file for your phpdaemon at /etc/init/phpdaemon.conf
    ```conf
    # Info
    @@ -30,11 +30,11 @@ script
    end script
    ```

    ##Starting & stopping your daemon:
    ## Starting & stopping your daemon:
    ```
    sudo service phpdaemon start
    sudo service phpdaemon stop
    ```
    ##Check if your daemon is running:
    ## Check if your daemon is running:
    ```sudo service myphpworker status```

  3. benedict-erwin created this gist Jul 2, 2019.
    40 changes: 40 additions & 0 deletions php-as-daemon.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,40 @@
    ##How to set it up:
    Create a config file for your phpdaemon at /etc/init/phpdaemon.conf
    ```conf
    # Info
    description "PHP Daemon"
    author "Benedict E. Pranata"
    # Events
    start on startup
    stop on shutdown
    # Automatically respawn
    # respawn the job up to 10 times within a 5 second period.
    respawn
    respawn limit 10 5
    # Check before running
    # exit if php script already running
    pre-start script
    if ps -ef | grep -v grep | grep phpdaemon; then
    stop; exit 0
    fi
    end script
    # Run the script!
    # Note, in this example, if your PHP script returns
    # the string "ERROR", the daemon will stop itself.
    script
    [ $(exec /usr/bin/php -f /path/to/your/phpdaemon.php) = 'ERROR' ] && ( stop; exit 1; )
    end script
    ```

    ##Starting & stopping your daemon:
    ```
    sudo service phpdaemon start
    sudo service phpdaemon stop
    ```
    ##Check if your daemon is running:
    ```sudo service myphpworker status```