Debug command line scripts with PhpStorm 2.1
Recently, we have been often asked to provide a detailed guide in debugging command line scripts. And finally here you are!
Currently PhpStorm supports two debug extensions, namely Xdebug and Zend Debugger. Before start debugging command line scripts you need to configure your development environment: the PHP interpreter and PhpStorm.
Configuring PHP interpreter
First of all, you need to tell PhpStorm which interpreter to use for launching scripts.
Next, you need to specify the extension you are going to use for debugging.
Now, let’s go ahead and start debugging!
Click the left gutter area at the line where you want to toggle a breakpoint.
Debugging Using Run Configurations
In PhpStorm, script execution capabilities are based on the ‘Run Configuration’ concept. See details in the PhpStorm on-line help:
PhpStorm enables using numerous run/debug configurations. Each run/debug configuration represents a named set of run/debug startup properties. When you perform run/debug operations with PhpStorm, you always start a process based on one of the existing configurations using its parameters.
PhpStorm comes with a number of pre-defined default run/debug configuration types for the various running and debugging issues.
PhpStorm features a dedicated ‘PHP Script’ run configuration for debugging command line scripts. Creating a run configuration from a PHP script context menu is as easy as a mouse click: just open the context menu and choose the ‘Create yourscriptname.php’ item if you need to specify a custom working directory or any script parameters.
Specify the custom working directory, the script parameters or enable the ‘Break at the first line’ debug mode (all these settings are optional), and click ‘OK’.
The new run configuration is saved. To start debugging, click the ‘Debug’ button on the toolbar.
If you don’t need any additional settings, just choose the ‘Debug’ item (by default, the working directory is the parent directory of the script).
As soon as the script execution stops at the breakpoint, open the ‘Debugger’ tab in the ‘Debug’ tool window. Examine the values of variables in the current frame or add a new expression to the list of watches, if necessary.
The results of the script execution are displayed in the ‘Console’ tab of the в ‘Debug’ tool window.
To customize an existing run configuration or create a new one manually, choose ‘Edit Configurations’ from the run configurations pop-up menu.
Add a new ‘PHP Script’ run configuration.
Or edit the existing one.
Debug using ‘listen debug connections’ button
Many of you have been fond of debugging scripts on the server using the ‘Start Listen PHP Debug Connections’ button.
Unfortunately, PhpStorm 2.1 does not support this mode for debugging CLI scripts and displays the following warning:
The problem has been solved in PhpStorm 3.0. So if you are keen on experimenting you can start using this CLI scripts debugging mode right now. We are happy to inform you that PhpStorm 3.0 EAP has been launched.
You may happen to get the following error message after script execution finishes: ‘Debug connection with Xdebug was not established’. This means that PhpStorm has not received an incoming connection from the debugger and the debug session has not been established. Most likely, the PHP interpreter is not configured correctly, for example, no debug extension is installed at all.
Develop with pleasure!
Working with Windows Azure SQL Database in PhpStorm
PhpStorm provides us the possibility to connect to Windows Azure SQL Database right from within the IDE. In this post, we’ll explore several options that are available for working with Windows Azure SQL Database (or database systems like SQL Server, MySQL, PostgreSQL or Oracle, for that matter): …
Change signature refactoring in PhpStorm
A very powerful refactoring is the Change signature refactoring in PhpStorm. It enables us to modify a function signature in many ways: we can change the function name, change its visibility, add, remove and reorder parameters as well as rename parameters. (more…)…
Folding for imports in PhpStorm 6.0
In PhpStorm 6, we've introduced code folding for imports. Any list of imports will now be folded into a single line. This greatly reduced clutter in your editor when having a lot of imports! (more…)…
Drag & Drop Project Files to Remote Hosts in PhpStorm
The Remote Host pane allows us to work directly on a remote server through FTP, FTPS, SFTP or a local/network folder. A lot of people asked us to add drag & drop to the Remote Host pane in PhpStorm. Good news: PhpStorm 6 comes with drag & drop as well as copy & paste support from the pro…