Debugging PHP behind Varnish

by , , revisited on

We have by far the largest RPM repository with dynamic stable NGINX modules and VMODs for Varnish 4.1 and 6.0 LTS. If you want to install NGINX, Varnish, and lots of useful modules for them, this is your one-stop repository to get all performance-related software.
You have to maintain an active subscription in order to be able to use the repository!

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.