![]() With Xdebug enabled your PHP code will run a lot slower. When refreshing the webpage you should first see this dialog indicating that PHPStorm got an incoming connection from Xdebug.Īfter clicking "Accept" you should hit your breakpoint.Ĭongratulations on your working Xdebug installation! A word on performance In my case I'm going to set a breakpoint in web/routes.php. Now go to the a piece of code in your project that should run when the web request is performed. That bug icon should turn green now indicating that the right cookies have been set. With the extension installed just point your browser to your site, click on the little bug icon next to the address bar, and choose "Debug". Personally I prefer using the Chrome Xdebug Helper extension. You can use the bookmarklets provided by Jetbrains to set those cookies. In order to trigger Xdebug a special cookie needs to be set on the webrequest. Read the PHPStorm docs to know more or just play around with it. Handy! Explaining the Xdebug UI in PHPStorm is out of scope for this article. In the console pane you can run arbitrary code. In the variables pane you can now inspect every single variable in the script. Got to the command line and execute php artisan inspire. Now let's run the command in which we just place a breakpoint. Open up routes/console.php and add a breakpoint by adding click in the sidebar left on the $this->comment(. Next up, select "Start listening for PHP Debug Connections" from the "Run" menu. Also uncheck "Force break at the first line when a script is outside the project". In the Debug preferences in PHPStorm make sure the debug port is set to the same value you specified in the ini file. Open up the newly created project in PHPStorm. Let's first test out if we can add a breakpoint to a script that is running on the command line. In that directory I ran laravel new laravel to create fresh copy of Laravel in the laravel directory. In my mac I've parked the /Users/freek/dev/sites directory. If you want to follow along with the rest of this post, create a fresh copy of laravel in a directory you parked with Valet. Port 9000 seems to be the default, but you may choose another port if you like. You can look up the meaning of the individual settings in the xdebug documentation. The above settings are needed to allow PHPStorm to connect to Xdebug. Go ahead and add these lines to that file: xdebug. By running php -ini you can verify that php is reading that setting file. In the last lines of the output of the installation indicated that there's a new ini file created at /usr/local/etc/php/7.1/conf.d/ext-xdebug.ini. To install xdebug, just run this command: brew install php71 - xdebug I'm going to assume that you have are running macOS, have latest version of PHP installed together with homebrew. In this post I'll show you easy it is to install and use it. Wouldn't it be nice if we could add a breakpoint to our code and be able to inspect the values of all variables in one go (and even execute the script line by line)? Enter Xdebug. But when encountering a complex bug this becomes tedious. When hitting a bug often I just put a dd() statement in the code to quickly inspect what's going on. On most of my day to day work I use Laravel Valet to develop locally.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |