Skip to content

Commit

Permalink
Merge pull request #1115 from markshust/feature/blackfire-helper-script
Browse files Browse the repository at this point in the history
New `bin/blackfire` script to enable, disable, or check status of Blackfire extension
  • Loading branch information
markshust authored Apr 13, 2024
2 parents 780133a + e6d11d4 commit 3b186b0
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 2 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,7 @@ It is recommended to keep your root docker config files in one repository, and y

- `bin/analyse`: Run `phpstan analyse` within the container to statically analyse code, passing in directory to analyse. Ex. `bin/analyse app/code`
- `bin/bash`: Drop into the bash prompt of your Docker container. The `phpfpm` container should be mainly used to access the filesystem within Docker.
- `bin/blackfire`: Disable or enable Blackfire. Accepts argument `disable`, `enable`, or `status`. Ex. `bin/blackfire enable`
- `bin/cache-clean`: Access the [cache-clean](https://github.com/mage2tv/magento-cache-clean) CLI. Note the watcher is automatically started at startup in `bin/start`. Ex. `bin/cache-clean config full_page`
- `bin/check-dependencies`: Provides helpful recommendations for dependencies tailored to the chosen Magento version.
- `bin/cli`: Run any CLI command without going into the bash prompt. Ex. `bin/cli ls`
Expand Down Expand Up @@ -346,7 +347,7 @@ It is recommended to keep your root docker config files in one repository, and y
- `bin/stop`: Stop all project containers.
- `bin/stopall`: Stop all docker running containers
- `bin/update`: Update your project to the most recent version of `docker-magento`.
- `bin/xdebug`: Disable or enable Xdebug. Accepts params `disable` (default) or `enable`. Ex. `bin/xdebug enable`
- `bin/xdebug`: Disable or enable Xdebug. Accepts argument `disable`, `enable`, or `status`. Ex. `bin/xdebug enable`

## Misc Info

Expand Down
3 changes: 2 additions & 1 deletion compose/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ help:
@echo "$(call red,===============================)"
@echo "$(call format,analyse,'Run `phpstan analyse` within the container to statically analyse code, passing in directory to analyse.')"
@echo "$(call format,bash,'Drop into the bash prompt of your Docker container.')"
@echo "$(call format,blackfire,'Disable or enable Blackfire. Accepts argument `disable`, `enable`, or `status`.')"
@echo "$(call format,cache-clean,'Access the cache-clean CLI.')"
@echo "$(call format,check-dependencies,'Provides helpful recommendations for dependencies.')"
@echo "$(call format,cli,'Run any CLI command without going into the bash prompt.')"
Expand Down Expand Up @@ -81,7 +82,7 @@ help:
@echo "$(call format,stop,'Stop all project containers.')"
@echo "$(call format,stopall,'Stop all docker running containers.')"
@echo "$(call format,update,'Update your project to the latest version of docker-magento.')"
@echo "$(call format,xdebug,'Disable or enable Xdebug.')"
@echo "$(call format,xdebug,'Disable or enable Xdebug. Accepts argument `disable`, `enable`, or `status`.')"


analyse:
Expand Down
55 changes: 55 additions & 0 deletions compose/bin/blackfire
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
#!/usr/bin/env bash

S=$(bin/clinotty cat /usr/local/etc/php/conf.d/blackfire.ini | grep -iGc '\;extension=blackfire.so');

blackfire_status() {
if [[ $S == 1 ]]; then
echo "Blackfire is disabled."
else
echo "Blackfire is enabled."
fi
}

blackfire_toggle() {
if [[ $S == 1 ]]; then
blackfire_enable
else
blackfire_disable
fi
}

blackfire_enable() {
if [[ $S == 1 ]]; then
bin/root sed -i -e 's/^;extension=blackfire.so/extension=blackfire.so/g' /usr/local/etc/php/conf.d/blackfire.ini
sleep 1
bin/restart phpfpm
echo "Blackfire has been enabled."
else
echo "Blackfire is already enabled."
fi
}

blackfire_disable() {
if [[ $S == 0 ]]; then
bin/root sed -i -e 's/^extension=blackfire.so/;extension=blackfire.so/g' /usr/local/etc/php/conf.d/blackfire.ini
sleep 1
bin/restart phpfpm
echo "Blackfire has been disabled."
else
echo "Blackfire is already disabled."
fi
}

firstArgLetter="$(echo "$1" | head -c 1)"

if [[ $firstArgLetter == "d" ]]; then
blackfire_disable
elif [[ $firstArgLetter == "e" ]]; then
blackfire_enable
elif [[ $firstArgLetter == "t" ]]; then
blackfire_toggle
elif [[ $firstArgLetter == "s" ]]; then
blackfire_status
else
printf "Please specify either 'disable', 'enable', 'status' or 'toggle' as an argument.\nEx: bin/blackfire status\n"
fi

0 comments on commit 3b186b0

Please sign in to comment.