PhpStorm gotcha: all PHP errors missing – “No errors found in this file”

If all your PHP errors and warnings suddenly disappear from your IDE editor window, despite you having the language level configured correctly etc., double check you haven’t turned on Reader Mode by accident, as by default it hides “error and warning highlighting and the inspection widget”.

Therefore you’ll see the message “No errors found in this file” when pressing F2, even though there are some.

Also by default, it turns on font ligatures (the fancier versions of =>, != etc.) so if you’re seeing those and wondering why, even though you have the boxes unticked in Preferences Editor > Font, or Editor > Color Scheme > Color Scheme Font / Console Font – again, check it’s not activated.

All this is configurable in Preferences > Editor > Reader Mode.

Note that Reader Mode is toggled on and off for individual files.

Jetbrains official docs

Tip for debugging complex MySQL queries if you have PhpStorm

  • Start a new scratch file (Mac: shift-cmd-N)
  • choose ‘MySQL’
  • Paste your query in
  • Reformat code (Mac: opt-cmd-L)

It’ll colour code and tidy everything, including lining up all the field names and aliases, neatly arranging the joins and the where clauses, plus you can hover over opening or closing brackets and see the opposite bracket highlighted.

This is useful when previewing raw Drupal view SQL and trying to understand it.

Troubleshooting PhpStorm – entire composer.json file shows as invalid

If you’re running the latest PhpStorm (2018.2.2 at time of writing) you might have a composer.json file that’s turned entirely yellow recently, even though it’s valid.

This happens when your composer.json has a “description” key and is due to this bug.

Workarounds:

  • Disable the inspection on the file
  • or remove the “description” temporarily

Troubleshooting: Where has the PhpStorm PHP 7 Compatibility Inspection gone?

If you’ve read this guide to checking PHP code for PHP 7 compatibility / used the inspection in the past, you may notice that it’s apparently disappeared – you’re supposed to be able to choose Run Inspection by Name… and choose PHP 7 Compatibility from the list.

This is because it’s been merged with the Language Level inspection.

So:

  • Preferences > Languages and Frameworks > PHP
  • set desired PHP Language Level under Development environment
  • Run inspection by name…
  • choose Language Level

Thanks to Jetbrains Support for helping me with that..

(Tested with PhpStorm 2017.1 EAP)

Obscure techniques for developers to minimise macOS CPU, disk I/O and power consumption

updated Sat 11 Feb 2017

Me writing this blog post

Assuming you’ve done all the obvious things, e.g.: remove unwanted apps, close apps that don’t need to be open, remove System Preference pane based apps you can do without, tidy the Login Items list, free up sufficient disk space, upgrade RAM, remove unnecessary browser extensions etc.

  • Exclude every website, Git repository and virtual machine on your Mac from Spotlight search.  This made an incredible difference in CPU activity for me (the mdworker and mds processes are what to look for in Activity Monitor).
  • Reduce the quantity of files in your Dropbox folder. It can’t cope with hundreds of thousands of files, or at least the indexing process on initial login can become lengthy and CPU intensive as you near Dropbox’s own estimate of 300,000 files.  Avoid having any Git repositories in there – just make sure you (a) have local backups (Time Machine only backs up certain files and directories) (b) you’re pushing to GitHub, Bitbucket or somewhere else off-site regularly.   Download AWS CLI and sync a .tar.gz occasionally with an S3 bucket.
  • If you use PhpStorm, turn off all the Language Injections you don’t need, turn off all the Inspections you don’t need and remove any unnecessary plugins.  You’ll almost certainly have a handful of candidates for each of those three areas – i.e. languages or frameworks you never use.  Just familiarise yourself with what’s available every now and again so if you do work on an unusual project you have a better chance of remembering to turn the necessary options back on.

(P.S. I’m still using El Capitan 10.11.6 and have no plans to upgrade for several months.)

Mac load average

$ sysctl -n vm.loadavg
{ 1.29 1.38 1.45 }

If you think the Mac load average seems high compared to Linux, here’s an explanation of how it’s calculated.  The CPU idle % is a more useful measure of how loaded your system is (the above measurement was taken with 97% idle CPU).

Troubleshooting remote debugging with Xdebug in PhpStorm

Updated Fri 7 Dec 2018.

Running Xdebug remotely is very useful – you can add breakpoints, inspect and modify the state of all variables/objects and type PHP code into a live console.  No need to manual add var_dump() statements etc.
It should save you a lot of time.

Unfortunately, while the setup should be straightforward, it’s easy to lose the programming time you save spending ages tweaking your Xdebug and PhpStorm configuration to get it to work in the first place. (In fact, I don’t think it’s worked correctly first time for me once.)

Also, you’ve probably got multiple projects, maybe running on different VMs, or using Docker (scroll down for special instructions for Docker on the Mac).

Drupal users:

There’s an element of “it just works” for Xdebug in the server/PhpStorm configuration when using Acquia Dev Desktop or Drupal VM.

Acquia Dev Desktop:

To enable/disable Xdebug:

edit /Applications/DevDesktop/php7_1/bin/php.ini
Uncomment the zend xdebug extension and turn on remote_enable

zend_extension=xdebug.so
xdebug.remote_enable = 1

Restart Apache – via one of:

  • the DevDesktop UI
  • the UI but with keyboard shortcuts, cmd-2 (stop) then cmd-1 (start)
  • CLI: /Applications/DevDesktop/apache/bin/apachectl -k restart

Drupal VM:

To turn on xdebug, make sure you’ve got:

php_xdebug_default_enable: 1

and:

installed_extras:
[...]
- xdebug

Then run vagrant provision to build/rebuild (this won’t affect your site). Leave PhpStorm set to port 9000.

Everyone else (non Drupal):

On other installations, here’s my growing checklist when I try to use Xdebug and nothing happens:

(The following is based on Xdebug 2.4.0RC4 and PhpStorm 2016.2.1)

Step 1: you should identify whether it’s a complete lack of communication between Xdebug and the IDE, or if PhpStorm is receiving the data the data but is setup wrong.

Close and restart PhpStorm.  Make sure PhpStorm is listening for PHP Debug Connections (bottom of Run menu, or green telephone icon top right), then reload your app in the browser.

What you’re looking for is either:

a) an ‘Incoming connection’ dialog the very first time you open a webpage of your app.
or
b) ‘Debug session was finished without being paused” in the Event Log.

Either of these confirms Xdebug is talking to PhpStorm and you can need not worry about your php.ini entries, the possibility you’re using the wrong port or that you forgot to trigger the bookmarklet – goto section B.

If nothing happened at all, go to section A.

A. Communication failure

  • Ensure the bookmarklet (recommended) or browser addon you’re using to start/stop debugging is activated.  You can use developer tools to verify the cookie is being sent.
  • Is Xdebug installed? (check phpinfo() output)
  • Does the Xdebug section of phpinfo() have this warning: “XDEBUG NOT LOADED AS ZEND EXTENSION”?  You’re meant to use zend_extension=xdebug.so, not extension=xdebug.so – go to the wizard, paste in your phpinfo() contents and it’ll generate a fully customised set of commands to run (< 2-3 mins) to download the xdebug extension and compile it for your system. (I’ve had this problem break one site – further info).
  • Make sure the bookmarklet’s cookie is correct, it should use PHPSTORM for the IDE key.    does the browser IDE key match xdebug.idekey in your php.ini file? (Verify correct config file is being loaded – have you confused configs for multiple versions or CLI/fpm – and correct value read from it by creating a test page with phpinfo() output.)  Correction: specifying xdebug.idekey in php.ini is unnecessary.  Note if you view the phpinfo() output, at the top of the Xdebug section there’s are two rows, listing the version and the IDE key. If xdebug.idekey is unset, XDebug will fall back to the value of $_SERVER[‘USER’], e.g. www-data, but regardless, as soon you activate your bookmarklet to start a debug session, the $_COOKIE[‘XDEBUG_SESSION’] is set to ‘PHPSTORM’ and that’s what’s passed through. (To test, start and stop a session whilst refreshing your phpinfo() page and watch the IDE key change.)
  • php.ini – ensure xdebug.remote_enable is set to 1 (then restart php-fpm, refresh page and keep an eye out for ‘Debug session was finished without being paused’ in the Event Log)
  • php.ini – you may well need xdebug.remote_connect_back = 1 too (again, restart php-fpm) – I’ve had multiple dev sites that require it – XDebug may be ignoring the connection from the debug client because it doesn’t match xdebug.remote_host, turning on remote_connect_back makes it ignore this and accept a connection from anywhere – make sure your dev machine is behind a firewall.
  • Check the ports match – this can get reset by mistake.  You may also need to use 9001 rather than the default 9000 if the latter is also being used by php-fpm on your server.  Also, open the Event Log and look for a message like “Can’t start listening for connections from ‘xdebug’: Port 9000 is busy”. Ports must be set correctly in two places – xdebug.remote_port and PhpStorm’s preferences (Languages & Frameworks > PHP > Debug > Xdebug)
  • You can verify both ends of this, the phpinfo() output will confirm what port Xdebug will send on.  You can verify PhpStorm is actually listening on the correct port with the lsof command (this example from macOS):
    wt$  sudo lsof -i :9001
    Password:
    COMMAND    PID USER   FD   TYPE             DEVICE SIZE/OFF NODE NAME
    phpstorm 80592   wt  330u  IPv4 0xaad56de5076720c3      0t0  TCP *:etlservicemgr (LISTEN)

    If PhpStorm is not listening this will be blank.

B. PhpStorm settings

  • By default Xdebug won’t do anything if no breakpoints were found. Check the Event Log pane – there will be a warning message, e.g. “Debug session was finished without being paused”. Is there one?
  • You may have configured Remote debugging to skip certain paths. In Preferences, check Languages & Frameworks > PHP > Debug > Skipped Paths (there’s no warning in Event Log if a script is skipped.)  Are you trying to verify an AJAX request, when, for example in WordPress, you have previously blocked admin-ajax.php to avoid spawning a new debug session every time autosave is triggered?
  • If PhpStorm is always stopping on the first line of the script but you don’t want it to, note that this option is specified in two separate places – one at the bottom of the run menu (“Break at first line in PHP scripts”) and also in Preferences (Languages & Frameworks > PHP > Debug > External connections)
  • Path mappings can get confusing. The left section is the project files that PhpStorm is looking at.  The column on the right needs to the path on the server – so you have a Vagrant box running on a Mac host, don’t use /Users/<name>/…, use /var/www/…, /usr/share/ etc.  Double check PhpStorm has saved what you’ve entered correctly.
  • If nothing’s happening, make sure all your previous debug sessions have finished. Press the stop button in the debug panel (cmd-F2 on Mac) and try reloading the page again. Also note also the Max. simultaneous connections setting.
  • Have you lost the Debug window, e.g. you minimised it and can’t find it again? Press cmd-5 or hover over the square in the far bottom-left of the screen.
  • Struggling to find the Path mappings dialog? Go to Preferences > Languages & Frameworks > PHP > Servers
  • Common mapping errors: Typically failing to map the document root (e.g. say in WordPress, you’ve mapped wp-admin and nothing else.)

Skipping the Incoming Connection dialog

Note: you might want to set the PHP_IDE_CONFIG environment variable on your server. This tells PhpStorm which path mapping configuration it should use so it doesn’t prompt you.  It needs to be written like this:

serverName=my-server.dev

where my-server.dev must match the name configured in Languages & Frameworks > PHP > Servers – as shown below:

PhpStorm - configuring the server name

PhpStorm’s Debug diagnostic tool

Go to: Run > Web Server Debug Validation (instructions here)

PhpStorm, Xdebug, Docker & Mac

Your Docker containers will have an IP address beginning 172.xxx.xxx.xxx (each container gets it’s own – check what it is)  You might assume that’d be enough to avoid conflicts with your real IP address or 127.0.0.1 when specifying xdebug.remote_host.

Note: on macOS, you need to create a symlink to your IP otherwise PhpStorm won’t be able to hear Xdebug.

  1. Create the alias:
    sudo ifconfig lo0 alias 10.254.254.254
  2. Put this new address (10.254.254.254) in:
    – your /etc/hosts file (an entry for your project’s hostname)
    – xdebug.remote_host (whether that’s in php.ini or an environment variable in docker-composer.yml)
    – PhpStorm in Preferences > Languages & Frameworks > PHP > Debug > DBGp Proxy > host

Restart everything and things should start working.

Related info:

PhpStorm troubleshooting – ideaVim stops working

IdeaVim is a popular plugin that adds vim shortcuts (e.g. hjkl navigation) to PhpStorm and similar products.

A rare bug Mac users may replicate one day: it’s possible to accidentally disable IdeaVim by pressing cmd-alt-V – the same shortcut as moving files in Finder.  PhpStorm does need to have focus; in my case I was typing the standard copy/paste/move shortcuts to transfer some files in the Project window.

You can see/toggle the Vim status with Tools > Vim Emulator (which won’t show up as a search result if you use shift-cmd-A and type ‘ideavim’).  It’s a handy shortcut to be aware of – temporarily turning Vim off may make it easier to complete certain refactoring tasks where you’re entering a new variable name.

IdeaVim’s settings are in vim_settings.xml in the WebIde100 folder (where the 100 at the end indicates version 10.0.*), in the event of a problem you can inspect or trash that file.