| name | dockergento-xdebug-toggle |
| description | Enables or disables Xdebug in Dockergento environment using hm debug-on and hm debug-off commands. Use when debugging PHP code, profiling performance, or optimizing development workflow. |
| allowed-tools | Read Grep Glob Bash Edit Write |
| model | sonnet |
Dockergento Xdebug Toggle
Manages Xdebug activation in Hiberus Dockergento environments using hm debug-on and hm debug-off commands for efficient PHP debugging and performance profiling.
When to Use
- Debugging PHP code with breakpoints
- Profiling application performance
- Analyzing code coverage for tests
- Tracing function calls and stack traces
- Investigating complex bugs
- Before/after performance testing
- Development workflow optimization
- Remote debugging sessions
Requirements
Execution Workflow
-
Assess debugging need
- Identify if Xdebug is required
- Check if already enabled
- Verify IDE configuration
- Plan debugging session
-
Enable Xdebug
- Run
hm debug-on
- Wait for container restart
- Verify Xdebug is active
- Start IDE debugging listener
-
Debug session
- Set breakpoints in IDE
- Trigger PHP execution
- Step through code
- Inspect variables
-
Disable Xdebug
- Run
hm debug-off
- Restore normal performance
- Verify Xdebug is disabled
-
Optimize workflow
- Keep Xdebug off by default
- Enable only when needed
- Monitor performance impact
Command Reference
Basic Commands
hm debug-on
hm debug-off
hm bash php -v | grep Xdebug
hm bash php -m | grep xdebug
hm bash php --ri xdebug
Verify Xdebug Status
if hm bash php -v | grep -q "Xdebug"; then
echo "Xdebug is ENABLED"
else
echo "Xdebug is DISABLED"
fi
hm bash php -v | grep Xdebug | head -n 1
hm bash php -i | grep xdebug
Implementation Patterns
Pattern 1: Automated Debug Session
#!/bin/bash
set -e
echo "Starting debug session..."
echo "Enabling Xdebug..."
hm debug-on
sleep 5
if ! hm bash php -v | grep -q "Xdebug"; then
echo "ERROR: Xdebug failed to enable"
exit 1
fi
echo "Xdebug enabled successfully"
echo "Xdebug version: $(hm bash php -v | grep Xdebug | head -n 1)"
echo ""
echo "IDE Setup Instructions:"
echo " 1. Start your IDE's debug listener (Listen for Xdebug)"
echo " 2. Set breakpoints in your code"
echo " 3. Access your site with ?XDEBUG_SESSION_START=PHPSTORM"
echo " 4. When done, run: hm debug-off"
echo ""
echo "Press Enter when done debugging..."
read
echo "Disabling Xdebug..."
hm debug-off
echo "Debug session completed"
Pattern 2: Performance Testing (Xdebug Off)
#!/bin/bash
set -e
echo "Disabling Xdebug for performance test..."
hm debug-off
sleep 3
if hm bash php -v | grep -q "Xdebug"; then
echo "ERROR: Xdebug still enabled, aborting test"
exit 1
fi
echo "Running performance test (Xdebug disabled)..."
time hm bash php bin/magento cache:flush
time hm bash php bin/magento indexer:reindex
echo "Performance test completed"
Pattern 3: Conditional Debugging
#!/bin/bash
if [ "${ENABLE_DEBUG}" = "true" ]; then
echo "Debug mode enabled"
hm debug-on
export XDEBUG_SESSION=PHPSTORM
else
echo "Debug mode disabled"
hm debug-off
fi
hm bash php bin/magento "$@"
Pattern 4: Profile Performance
#!/bin/bash
set -e
PROFILE_DIR="var/profiling"
TIMESTAMP=$(date +%Y%m%d_%H%M%S)
echo "Starting profiling session..."
hm debug-on
hm bash mkdir -p "${PROFILE_DIR}"
export XDEBUG_TRIGGER=1
echo "Executing script with profiling enabled..."
hm bash php -d xdebug.mode=profile \
-d xdebug.output_dir="${PROFILE_DIR}" \
-d xdebug.profiler_output_name="profile_${TIMESTAMP}.%p.cachegrind" \
bin/magento indexer:reindex
echo "Profiling data saved to: ${PROFILE_DIR}"
echo "Analyze with: qcachegrind ${PROFILE_DIR}/profile_${TIMESTAMP}.*.cachegrind"
hm debug-off
echo "Profiling completed"
Pattern 5: IDE Configuration Helper
#!/bin/bash
set -e
IDE="${1:-vscode}"
echo "Setting up ${IDE} for Xdebug debugging..."
case "${IDE}" in
vscode)
cat > .vscode/launch.json <<'EOF'
{
"version": "0.2.0",
"configurations": [
{
"name": "Listen for Xdebug",
"type": "php",
"request": "launch",
"port": 9003,
"pathMappings": {
"/var/www/html": "${workspaceFolder}"
},
"log": true,
"xdebugSettings": {
"max_data": 65535,
"show_hidden": 1,
"max_children": 100,
"max_depth": 5
}
},
{
"name": "Launch currently open script",
"type": "php",
"request": "launch",
"program": "${file}",
"cwd": "${fileDirname}",
"port": 9003
}
]
}
EOF
echo "VS Code configuration created: .vscode/launch.json"
;;
phpstorm)
echo "PhpStorm configuration:"
echo " 1. Go to: Settings > PHP > Debug"
echo " 2. Set Xdebug port: 9003"
echo " 3. Enable 'Can accept external connections'"
echo " 4. Go to: Settings > PHP > Servers"
echo " 5. Add server:"
echo " - Name: docker"
echo " - Host: localhost"
echo " - Port: 80"
echo " - Use path mappings:"
echo " ${PWD} -> /var/www/html"
echo " 6. Enable toolbar debug listener"
;;
*)
echo "Unknown IDE: ${IDE}"
echo "Supported: vscode, phpstorm"
exit 1
;;
esac
echo ""
echo "Next steps:"
echo " 1. Run: hm debug-on"
echo " 2. Start IDE debug listener"
echo " 3. Set breakpoints"
echo " 4. Access: http://localhost/?XDEBUG_SESSION_START=PHPSTORM"
Xdebug Configuration
Check Current Configuration
hm bash php -i | grep xdebug
hm bash php -i | grep -E "xdebug\.(mode|client_host|client_port|start_with_request)"
Common Xdebug Settings (Xdebug 3)
xdebug.mode=debug,develop,coverage,profile,trace
xdebug.client_host=host.docker.internal
xdebug.client_port=9003
xdebug.start_with_request=trigger
xdebug.idekey=PHPSTORM
xdebug.log=/var/log/xdebug.log
Debugging Workflows
Workflow 1: Breakpoint Debugging
hm debug-on
curl "http://localhost/?XDEBUG_SESSION_START=PHPSTORM"
hm debug-off
Workflow 2: CLI Script Debugging
hm debug-on
hm bash php -d xdebug.start_with_request=yes bin/magento catalog:product:import
hm debug-off
Workflow 3: Remote Debugging
hm debug-on
ssh -R 9003:localhost:9003 user@remote-server
curl "http://localhost/?XDEBUG_SESSION_START=PHPSTORM"
Performance Impact
Xdebug Overhead
#!/bin/bash
set -e
ITERATIONS=10
echo "Measuring Xdebug performance impact..."
echo ""
hm debug-off
sleep 3
echo "Testing WITHOUT Xdebug..."
TOTAL_WITHOUT=0
for i in $(seq 1 ${ITERATIONS}); do
START=$(date +%s%N)
hm bash php bin/magento cache:flush > /dev/null 2>&1
END=$(date +%s%N)
DURATION=$(( (END - START) / 1000000 ))
TOTAL_WITHOUT=$((TOTAL_WITHOUT + DURATION))
echo " Iteration ${i}: ${DURATION}ms"
done
AVG_WITHOUT=$((TOTAL_WITHOUT / ITERATIONS))
echo ""
echo "Testing WITH Xdebug..."
hm debug-on
sleep 3
TOTAL_WITH=0
for i in $(seq 1 ${ITERATIONS}); do
START=$(date +%s%N)
hm bash php bin/magento cache:flush > /dev/null 2>&1
END=$(date +%s%N)
DURATION=$(( (END - START) / 1000000 ))
TOTAL_WITH=$((TOTAL_WITH + DURATION))
echo " Iteration ${i}: ${DURATION}ms"
done
AVG_WITH=$((TOTAL_WITH / ITERATIONS))
hm debug-off
echo ""
echo "Results:"
echo " Average WITHOUT Xdebug: ${AVG_WITHOUT}ms"
echo " Average WITH Xdebug: ${AVG_WITH}ms"
echo " Overhead: $((AVG_WITH - AVG_WITHOUT))ms"
echo " Slowdown factor: $((AVG_WITH * 100 / AVG_WITHOUT))%"
Troubleshooting
Xdebug Not Connecting
hm bash php -v | grep Xdebug
hm bash php --ri xdebug
hm bash cat /var/log/xdebug.log
hm bash php -d xdebug.start_with_request=yes -r "echo 'Testing Xdebug connection';"
netstat -an | grep 9003
docker inspect dockergento_php | grep IPAddress
Port Conflicts
lsof -i :9003
kill $(lsof -t -i:9003)
hm bash php -d xdebug.client_port=9001 bin/magento
Connection Timeout
hm bash php -d xdebug.connect_timeout_ms=2000 bin/magento
sudo ufw status
sudo ufw allow 9003/tcp
Best Practices
- Keep Xdebug disabled by default (5-10x performance penalty)
- Enable only when actively debugging
- Use trigger mode (start_with_request=trigger)
- Configure IDE path mappings correctly
- Use Xdebug 3 (faster than Xdebug 2)
- Disable for performance testing (always)
- Close debug sessions when done
- Monitor Xdebug logs for connection issues
- Use profiling mode for performance analysis
- Document IDE setup for team members
Common Use Cases
Debug Magento Plugin
hm debug-on
curl "http://localhost/admin/catalog/product/save/?XDEBUG_SESSION_START=PHPSTORM" \
-X POST -d "product[sku]=test"
hm debug-off
Debug REST API
hm debug-on
curl "http://localhost/rest/V1/products/SKU123?XDEBUG_SESSION_START=PHPSTORM" \
-H "Authorization: Bearer <token>"
hm debug-off
Debug CLI Command
hm debug-on
hm bash php -d xdebug.start_with_request=yes \
bin/magento customer:hash:upgrade
hm debug-off
Integration Examples
Git Hook (Pre-Commit)
#!/bin/bash
if hm bash php -v | grep -q "Xdebug"; then
echo "WARNING: Xdebug is enabled"
echo "Run: hm debug-off"
exit 1
fi
CI/CD Integration
test:
before_script:
- hm debug-off
script:
- hm bash php bin/magento setup:di:compile
- hm bash php vendor/bin/phpunit
Quality Bar
- Xdebug enables/disables without errors
- Container restarts successfully
- IDE connects to Xdebug properly
- Breakpoints trigger correctly
- Path mappings configured correctly
- Xdebug disabled by default (performance)
- Debug session closes cleanly
- No port conflicts
- Logs show successful connections
- Team documentation updated