Cấu hình để debugging Drush commands với Xdebug và PHPStorm

Cấu hình để debugging Drush commands với Xdebug và PHPStorm

Oftentimes, I run into issues with drush commands that needed more debugging power than dpm() provides. In search for a way to debug PHP scripts from the CLI, or drush commands more specifically, I stumbled upon PHPStorm’s Zero-configuration Debugging which turned out to be perfect for the job.

First, you will need Xdebug installed. http://xdebug.org/ has some excellent documentation on installing XDebug. For OSX users, I would recommend using homebrew with the formulae here https://github.com/josegonzalez/homebrew-php.

In the CLI, we will need to set the XDEBUG_CONFIG variable.

In bash,

export XDEBUG_CONFIG="idekey=PHPSTORM"

Once Xdebug is installed and the XDEBUG_CONFIG variable set up, start a new project in PHPStorm. Click on the Magic Button to "Start Listen PHP Debug Connections"

Cấu hình để debugging Drush commands với Xdebug và PHPStorm

In the CLI, we can then run any drush command inside the drupal docroot and a breakpoint should trigger on the first line of drush.php.

Breakpoint

Set up breakpoints and debug like you normally would. As long as PHPStorm is listening for a connection and the XDEBUG_CONFIG variable is set, any PHP script run on the CLI will trigger the debugger to break on the first line of the script. Once you are done with debugging, click the Magic Button again to "Stop Listen PHP Debug Connections".

Drush commands always trigger a break at the first line, unless drush is included in the project. When that gets a little old, uncheck "Force break at the first line when a script is outside the project" to stop the break at the first line.

Force break at the first line when a script is outside the project

I am in the debugger so much I ended up with the xdebug.idekey set up in my php.ini permanently.

xdebug.idekey="PHPSTORM";

That way the XDEBUG_CONFIG variable is not necessary anymore. In fact, this way any PHP activities including browsing a local site will pass through the debugging as long as PHPStorm is listening for a connection.

Bạn thấy bài viết này như thế nào?: 
No votes yet
Ảnh của Khanh Hoang

Khanh Hoang - Kenn

Kenn is a user experience designer and front end developer who enjoys creating beautiful and usable web and mobile experiences.

Tìm kiếm bất động sản

 

Advertisement

 

jobsora

Dich vu khu trung tphcm

Dich vu diet chuot tphcm

Dich vu diet con trung

Quảng Cáo Bài Viết

 
Candy Crush - ứng dụng hot nhất trên iPhone năm 2013

Candy Crush - ứng dụng hot nhất trên iPhone năm 2013

Apple đã công bố những chương trình miễn phí được tải nhiều nhất trên hệ điều hành iOS và nhiều trong số đó là các ứng dụng rất quen thuộc với người sử dụng tại Việt Nam.

PageRank là gì?

Google Pagerank là gì?

Trước tiên chúng ta tìm hiểu lại khái niệm website một chút. Website là tập hợp các trang web, tương tự như một cuốn sách là tập hợp các trang sách. Với các bạn đã từng thiết kế website chắc không xa lạ gì với khái niệm này.

Phân tích các thành phần đặc trưng của các web rác - spammy website, blog

Phân tích các thành phần đặc trưng của các web rác - spammy website, blog

Phân tích các thành phần đặc trưng của các web rác - spammy website, blog. Các phương pháp tối ưu lâu dài - white hat search engine optimization.

Công ty diệt chuột T&C

 

Diet con trung