Return variable value in Apache

I wouldn’t say that having Apache return the variable’s value rather than PHP is an optimisation. Rather, using PHP to return the variable’s value would be an ‘unoptimisation’. It’s akin to using PHP to serve a file rather than Apache just serving the file itself. It could be argued that it’s also worse in terms of clarity as you effectively have a longer stack when using Apache + PHP compared to just Apache.

It is possible for Apache to set the response body without use of a file, e.g. see the first example here: Apache Custom Error Responses. Unfortunately that’s only for error responses, and variables aren’t available to use as the response body either.