Blog

  • Debugging Empty WP-CLI Output: Finding the Problematic Plugin

    When WP-CLI commands mysteriously return no output, it’s often due to a misbehaving plugin. Here’s a quick script that helped me identify the culprit:

    bash
    for plugin in $(wp plugin list --field=name --skip-plugins); do
        echo -e "\033[1;34m-----------------------------------------\033[0m"
        echo -e "\033[1;33mTesting with --skip-plugins=$plugin...\033[0m"
        
        output=$(wp eval 'echo "test";' --skip-plugins="$plugin")
        
        if [ ! -z "$output" ]; then
            echo -e "\033[1;32mSuccess! Output: $output\033[0m"
            echo -e "\033[1;31mProblem likely caused by: $plugin\033[0m"
            echo -e "\033[1;34m-----------------------------------------\033[0m"
            break
        else
            echo -e "\033[1;31mNo output. Moving to the next plugin.\033[0m"
        fi
    done
    

    This script iterates through each plugin, disabling them one at a time until WP-CLI output is restored. When output appears, you’ve found your problematic plugin.

    The script uses color coding for better visibility:

    • Blue: Separators
    • Yellow: Current test
    • Green: Success
    • Red: Issues/problematic plugin

    Save this as debug-wpcli.sh and run it from your WordPress root directory.

    Happy debugging!

  • Quick MySQL Connection Monitoring for Lazy Admins

    Ever needed to quickly check who’s hogging your MySQL server? Here’s a one-liner I keep in my toolbox for when things get sluggish.

    bash
    mysql -e "select user,count(*) FROM information_schema.processlist group by user order by count(*) desc;"
    

    This gives you a quick snapshot of connections per user. But the real magic happens when you need to watch it in real-time:

    bash
    while true; do mysql -e "select user,count(*) FROM information_schema.processlist group by user order by count(*) desc;"; sleep 5; done
    

    This will refresh every 5 seconds. Perfect for catching that misbehaving WordPress plugin or runaway script that’s creating too many connections.

    I’ve used this countless times when developers swear “it can’t be our code” causing connection issues. Spoiler: it usually is.

    Pro tip: Adjust the sleep value based on your needs. I use 5 seconds, but you might want faster/slower updates depending on what you’re troubleshooting.