PhpStorm Feature of the day: Streamlining Debugging with Pre-Run Actions

Did you know you can execute additional tasks before re-running or debugging your scripts? This feature can save you significant time and effort, especially when working with resources like Redis or other external dependencies. Let me share an example where this approach made my workflow much smoother.

I was running a CLI script that was setting a Mutex in Redis, but it quickly became a pain point. Each time I needed to run it again or debug, I faced one of two annoying choices: either wait for the 10-minute Mutex expiration or manually delete the key in Redis. If I forgot the latter, I’d get frustrated at hitting a wall repeatedly. To address this, I created a simple configuration (as shown in screen 1) and linked it to an action (screen 2), allowing me to automate the cleanup process. This saved me from repetitive manual tasks and let me focus on solving actual problems.

Screen 1
Screen 2

This approach has a broad range of applications. For example, you can use it to reset or clear caches in Redis, files, or databases, ensuring a clean state before every run. It can also help preset known configurations, add a task to a queue that you are working on to make sure it always has at least one task, or enforce other prerequisites seamlessly. The possibilities are endless, and the best part? You can chain multiple actions to execute them in sequence. This means that whether you’re initializing test data, clearing stale states, or priming queues, it’s all done in one go.

Now, when I press Shift + Alt + X to run or Shift + Alt + D to debug (in my keymap), the Mutex cleanup happens automatically. To keep things organized and avoid confusion later, I suggest creating a separate run configuration for specific tasks like these. This way, you won’t forget to remove the additional configurations once they’re no longer needed, and your main workflow remains clean and streamlined. With this setup, my debugging process became faster and far less frustrating, and yours can too!

Leave a Reply

Your email address will not be published. Required fields are marked *