SwooleFor: Automatically restart Swoole service by monitoring file changes

Keywords: PHP JSON Python Apache

SwooleFor

Monitor changes in your Swoole program files and restart the server automatically - for development

Monitor for any changes in your swoole application and automatically restart the server - perfect for development

SwooleFor s are positioned as PHP versions nodemon, node-dev

Use of the project mix-phar Development

Depend extensions

Download

Use (Usage)

Execute script commands:

php swoolefor.phar --exec="php app.php arg..."

If disable_functions disables the proc_open method, execute as follows:

php -d disable_functions='' swoolefor.phar --exec="php app.php arg..."

Successful start-up:

   _____                     __     ______          
  / ___/      ______  ____  / /__  / ____/___  _____
  \__ \ | /| / / __ \/ __ \/ / _ \/ /_  / __ \/ ___/
 ___/ / |/ |/ / /_/ / /_/ / /  __/ __/ / /_/ / /    
/____/|__/|__/\____/\____/_/\___/_/    \____/_/  Version: 1.1.1, Swoole: 4.4.0

[info] 2019-08-14 11:51:05.937 <920> [message] executor start, exec: [php /data/bin/mix-httpd start]
[info] 2019-08-14 11:51:05.938 <920> [message] fork sub process, pid: 921
[info] 2019-08-14 11:51:05.939 <920> [message] monitor start
[info] 2019-08-14 11:51:05.939 <920> [message] watch: /data
[info] 2019-08-14 11:51:05.939 <920> [message] delay: 3s
[info] 2019-08-14 11:51:05.939 <920> [message] ext: .php,.json

All command parameters

php swoolefor.phar --help
  • -e, --exec Swoole application or other script start command
  • -d, --daemon Run in the background
  • --watch Watch code file directory
  • --delay File change delay processing (seconds)
  • --ext Monitor only changes to these extensions
  • --signal Send this signal to the process

Execute script commands

--exec Internal can be any command, must beAbsolute Path,Must beResident Procedures Executed by Front Desk (Otherwise, it will lead to continuity. fork process)

php swoolefor.phar --exec="php app.php"

Short parameters can also be used

php swoolefor.phar -e "php app.php"

Execute non-PHP scripts

  • node
php swoolefor.phar --exec="node app.js"
  • python
php swoolefor.phar --exec="python app.py"

Execution in the background

SwooleFor itself can be executed in the background so that it can be disconnected from the terminal and added -- daemon.

php swoolefor.phar --exec="node app.js" --daemon

Short parameters can also be used

php swoolefor.phar --exec="node app.js" -d

Specify a monitoring directory

The default value of -- watch is the current directory of the script in the exec parameter, and if the script is in the bin directory, the directory at the next level will be monitored.

// Automatically monitor / data directories
php swoolefor.phar --exec="php /data/bin/app.php"

Specify other directories to monitor

php swoolefor.phar --exec="php app.php" --watch=/tmp

Delayed execution restart

When many files are updated, we don't want the program to reboot frequently, so we need to set a time to delay the reboot, only when the set time is reached.

delay defaults to 3s

php swoolefor.phar --exec="php app.php" --delay=5

Expansion of specified observations

--ext Default is php,json,Configurable when other extensions need to be observed

php swoolefor.phar --exec="php app.php" --ext=php,json,ini

Signal sent on restart

When a program restarts, terminating a process is accomplished by signaling the process, when we need to specify a signal.

-- signal defaults to 15

php swoolefor.phar --exec="php app.php" --signal=1

Common Signal Tables

signal value
SIGTERM 15
SIGKILL 9
SIGHUP 1
... ...

Supporting popular Woole frameworks

  • MixPHP:
php swoolefor.phar -e "php /data/bin/mix-httpd start -c /data/applications/http/config/httpd.php"
  • Swoft:
php swoolefor.phar -e "php /data/bin/swoft http:start"
  • EasySwoole:
php swoolefor.phar -e "php /data/bin/easyswoole start"
  • laravel-s
php swoolefor.phar -e "php /data/bin/laravels start"

License

Apache License Version 2.0, http://www.apache.org/licenses/

Posted by AwptiK on Tue, 13 Aug 2019 23:24:07 -0700