Debugging on Platform.sh

We are in the process of deploying a lot of sites on to the excellent Platform.sh infrastructure at the moment.  As with all these things, we hit a few snags along the way.  The way that we worked around this was to install the Xdebug extension and use it to step through the code.

Firstly you need to enable the extension. Edit your .platform.app.yaml file to add the extension.

runtime:
    extensions:
      - xdebug

You will need to check that code in and deploy it to one of your containers.

Now that you have XDebug installed, you need to get it to talk to your local IDE.  The easiest way is via an ssh tunnel.  Open a terminal and run the following command, changing the user to that of your project hash.

ssh -R 9000:localhost:9000 bvzmhsdbu6g3g-master@ssh.eu.platform.sh

If you don’t know where to find your ssh details, it is in the web interface under Access Info.  Click the clipboard to the right to copy the ssh connection.

ssh access settings

Assuming that you have your IDE set up to accept Xdebug settings, you can now start it listening on port 9000 and tell the website to start debugging.

Xdebug helper in the address barIf you’re using Google Chrome, then Xdebug helper is a great little icon that sits in your address bar.  Rather than you having to add an attribute to the address, you can simply click this friendly little bug to add a cookie to the request.

Drupal and DNS Prefetch

In a bid to help you gain performance from your web apps, a new feature introduced with HTML5 is the ability to prefetch DNS resources.  Currently widely supported (Firefox 3.5+, Chrome, Safari 5+ and IE 9+), prefetching is where your browser will in the background to a DNS lookup for the addresses that you give. This means when it comes to access a resource at a host, it can skip the DNS lookup, thus saving precious milliseconds on your load time.

This is one way you can implement prefetching with Drupal, inside a THEME_prerpocess_page() hook.

function MYTHEME_preprocess_page(&$variables, $hook) {
    drupal_add_html_head(array(
    '#tag' => 'link',
    '#attributes' => array(
      'rel' => 'dns-prefetch',
      'href' => '//www.googletagmanager.com',
    ),
  ), 'googletagmanager_dns_prefetch');
}

This will produce the following html in the head of your site

<link rel="dns-prefetch" href="//www.googletagmanager.com" />