Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New bin/blackfire script to enable, disable, or check status of Blackfire extension #1115

Merged
merged 1 commit into from
Apr 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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