Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Wiki Markup
{align:right}
{html}
<a href="https://twitter.com/share" class="twitter-share-button" data-via="phpstorm">Tweet</a>
<script>!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0],p=/^http:/.test(d.location)?'http':'https';if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src=p+'://platform.twitter.com/widgets.js';fjs.parentNode.insertBefore(js,fjs);}}(document, 'script', 'twitter-wjs');</script>
<span id="fb-root"></span>
<script>(function(d, s, id) {
  var js, fjs = d.getElementsByTagName(s)[0];
  if (d.getElementById(id)) return;
  js = d.createElement(s); js.id = id;
  js.src = "//connect.facebook.net/en_US/sdk.js#xfbml=1&version=v2.0";
  fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));</script>
<span class="fb-like" data-layout="button_count" data-action="like" data-show-faces="true" data-share="false" style="position:relative;margin-left:-20px;top:-5px;"></span>
<script type="text/javascript" src="https://apis.google.com/js/plusone.js"></script>
<g:plusone size="medium"></g:plusone>
{html}
{align}

Include Page
Social Buttons PhpStorm
Social Buttons PhpStorm

 

Note
iconfalse

Not all PHP applications are web applications. Many of us write scripts that run in the PHP CLI. Our own command line tools, our own daemons, a message queue processing application and other types of applications typically run from the command line. In this tutorial, we'll see how we can debug PHP CLI scripts with PhpStorm.

There are various ways to start a debugging session. We can start a session from within PhpStorm and make it start our script and attach the debugger to it. Another way is to let PhpStorm listen for incoming debugger connections and start the script outside the IDE. We'll have a look at both options.

Table of Contents

Tip

Be sure to check the other tutorials about debugging PHP code with PhpStorm to learn more, including troubleshooting tips and advanced debugging techniques.

...

Expand
titleStarting the script with Xdebug

Xdebug has various configuration options which we can use to let the PHP interpreter reach out to PhpStorm. These parameters have to be passed to the PHP interpreter using the -d command line switch. A more convenient way will be to set an environment variable so we don't have to provide the -d switches all the time.

Using PHP command line switches

To start our script with debugging, we can launch PHP with several switches:

Code Block

php -dxdebug.remote_enable=1 -dxdebug.remote_mode=req -dxdebug.remote_port=9000 -dxdebug.remote_host=127.0.0.1 -dxdebug.remote_connect_back=0 path/to/script.php

Using an environment variable

To start our script with debugging, we can set an environment variable that configures Xdebug:

Code Block

Windows:
set XDEBUG_CONFIG="remote_enable=1 remote_mode=req remote_port=9000 remote_host=127.0.0.1 remote_connect_back=0"

Linux / Mac OS X:
export XDEBUG_CONFIG="remote_enable=1 remote_mode=req remote_port=9000 remote_host=127.0.0.1 remote_connect_back=0"

Next, we can start our script like we would normally do:

Code Block

php path/to/script.php
Tip

Optionally, we can use Xdebug's remote_autostart setting to always start a debugging session for every script that is run.

Expand
titleStarting the script with Zend Debugger

Zend Debugger has various configuration options which we can use to let the PHP interpreter reach out to PhpStorm. These parameters have to be passed to the PHP interpreter using an environment variable.

First, we have to set the QUERY_STRING environment variable:

Code Block

Windows:
set QUERY_STRING="start_debug=1&debug_host=127.0.0.1&no_remote=1&debug_port=10137&debug_stop=1"

Linux / Mac OS X:
export QUERY_STRING="start_debug=1&debug_host=127.0.0.1&no_remote=1&debug_port=10137&debug_stop=1"

Next, we can start our script like we would normally do:

Code Block

php path/to/script.php

To tell the PhpStorm which path mapping configuration should be used for a connection from certain machine, the value of the PHP_IDE_CONFIG environment variable should be set to serverName=SomeName, where SomeName is the name of the server configured in Settings / Preferences | Languages & Frameworks | PHP | Servers:

Code Block

Windows:
set PHP_IDE_CONFIG="serverName=SomeName"

Linux / Mac OS X:
export PHP_IDE_CONFIG="serverName=SomeName"

...

Tip

If the script that is being debugged is not a part of the project that's open in PhpStorm, the IDE will still open the script in the editor and pause execution at the first statement. This makes it possible to quickly debug any PHP CLI script, even if we don't have a PhpStorm project for it yet.

Wiki Markup
{align:right}
{html}
<a href="https://twitter.com/share" class="twitter-share-button" data-via="phpstorm">Tweet</a>
<script>!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0],p=/^http:/.test(d.location)?'http':'https';if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src=p+'://platform.twitter.com/widgets.js';fjs.parentNode.insertBefore(js,fjs);}}(document, 'script', 'twitter-wjs');</script>
<span id="fb-root"></span>
<script>(function(d, s, id) {
  var js, fjs = d.getElementsByTagName(s)[0];
  if (d.getElementById(id)) return;
  js = d.createElement(s); js.id = id;
  js.src = "//connect.facebook.net/en_US/sdk.js#xfbml=1&version=v2.0";
  fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));</script>
<span class="fb-like" data-layout="button_count" data-action="like" data-show-faces="true" data-share="false" style="position:relative;margin-left:-20px;top:-5px;"></span>
<script type="text/javascript" src="https://apis.google.com/js/plusone.js"></script>
<g:plusone size="medium"></g:plusone>
{html}
{align}

Include Page
Social Buttons PhpStorm
Social Buttons PhpStorm