Site icon GetPageSpeed

Debugging PHP behind Varnish

Varnish

Varnish

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.

Exit mobile version