Debugging PHP behind Varnish

by , , revisited on

We have by far the largest RPM repository with NGINX module packages and VMODs for Varnish. If you want to install NGINX, Varnish, and lots of useful performance/security software with smooth yum upgrades for production use, this is the repository for you.
Active subscription is required.

None or very little development should be done on a production box, but indeed, sometimes you need to troubleshoot things at live site.

Varnish makes it a bit troublesome to see why a particular request to a page failed: it will mask fatal PHP errors with its own “Backend Fetch Failed” error. This makes it less obvious that there’s a problem with your PHP code and makes you immediately blame Varnish.

You can temporarily make Varnish pass through its cache by piping all requests directly to the configured backend. In this way, it will work absolutely the same in regards to debugging PHP code (as if Varnish isn’t actually there!). My steps for this are:

  1. Open your VCL file and immediately after sub vcl_recv {, place a line return (pipe);
  2. Reload your Varnish configuration with service varnish reload or systemctl reload varnish (depends on your Linux distro).

To go back to caching (production setting), remove the line and reload Varnish again. No downtime when doing these steps.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: