github.com/drud/ddev@v1.21.5-alpha1.0.20230226034409-94fcc4b94453/pkg/ddevapp/global_dotddev_assets/commands/web/blackfire (about)

     1  #!/bin/bash
     2  
     3  #ddev-generated: Remove this line to take over this script
     4  ## Description: Enable or disable blackfire.io profiling
     5  ## Usage: blackfire start|stop|on|off|enable|disable|true|false|status
     6  ## Example: "ddev blackfire" (default is "on"), "ddev blackfire off", "ddev blackfire on", "ddev blackfire status"
     7  ## ExecRaw: false
     8  ## Flags: []
     9  
    10  function enable {
    11    if [ -z ${BLACKFIRE_SERVER_ID} ] || [ -z ${BLACKFIRE_SERVER_TOKEN} ]; then
    12      echo "BLACKFIRE_SERVER_ID and BLACKFIRE_SERVER_TOKEN environment variables must be set" >&2
    13      echo "See docs for how to set in global or project config" >&2
    14      echo "For example, ddev config global --web-environment-add=BLACKFIRE_SERVER_ID=<id>,BLACKFIRE_SERVER_TOKEN=<token>"
    15      exit 1
    16    fi
    17    phpdismod xhprof xdebug
    18    phpenmod blackfire
    19    killall -USR2 php-fpm && killall -HUP nginx
    20    # Can't use killall here because it kills this process!
    21    pid=$(ps -ef | awk '$8~/^blackfire.*/ { print $2 }' 2>/dev/null)
    22    if [ "${pid}" != "" ]; then kill $pid; fi
    23    nohup blackfire agent:start --log-level=4 >/tmp/blackfire_nohup.out 2>&1 &
    24    sleep 1
    25    echo "Enabled blackfire PHP extension and started blackfire agent"
    26    exit
    27  }
    28  function disable {
    29    phpdismod blackfire
    30    killall -USR2 php-fpm
    31    # Can't use killall here because it kills this process!
    32    pid=$(ps -ef | awk '$8~/^blackfire.*/ { print $2 }' 2>/dev/null)
    33    if [ "${pid}" != "" ]; then kill ${pid}; fi
    34    echo "Disabled blackfire PHP extension and stopped blackfire agent"
    35    exit
    36  }
    37  
    38  
    39  if [ $# -eq 0 ] ; then
    40    enable
    41  fi
    42  
    43  case $1 in
    44    on|true|enable|start)
    45      disable_xdebug
    46      enable
    47      ;;
    48    off|false|disable|stop)
    49      disable
    50      ;;
    51    status)
    52      php --version | grep "with blackfire" >/dev/null 2>&1
    53      phpstatus=$?
    54      # Can't use killall here because it kills this process!
    55      agentstatus=$(ps -ef | awk '$8~/^blackfire.*/ { print $2 }' 2>/dev/null)
    56      if [ ${phpstatus} -eq 0 ]; then echo "blackfire PHP extension enabled"; else echo "blackfire PHP extension disabled"; fi
    57      if [ "${agentstatus}" != "" ]; then echo "blackfire agent running"; else echo "blackfire agent not running"; fi
    58      if [ ${phpstatus} -eq 0 ]; then printf "probe version %s\n" "$(php -v | awk  -F '[ ,\~]+' '/blackfire/{ print $4; }')"; fi
    59      printf "blackfire version %s\n" "$(blackfire version | awk '{print $3;}')"
    60      ;;
    61  
    62    *)
    63      echo "Invalid argument: $1"
    64      ;;
    65  esac